import form question

Hello,
I am trying to preform a relative import of a variable like this:

import ..common.filename as common

The file common.py is two levels above the file that is needing the filename variable.

I haven't tried this as of yet but I thought it was possible...

Can any tell be the correct way to import parent modules?

thanks
Scott

···

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.11/44 - Release Date: 7/8/2005

Hello,
I am trying to preform a relative import of a variable like this:

import ..common.filename as common

The file common.py is two levels above the file that is needing the
filename variable.

I haven't tried this as of yet but I thought it was possible...

Can any tell be the correct way to import parent modules?

thanks
Scott

You can load a file directly, bypassing the normal import mechanism,
using the methods in the imp module.

···

On 7/9/05, scott <scott@ebbyfish.com> wrote:

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.11/44 - Release Date: 7/8/2005

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

You can load a file directly, bypassing the normal import mechanism,

> using the methods in the imp module.

How? I looked at what little was available in then doc strings, but I can't get anything to work, just errors. :frowning:

Scott

Chris Mellon wrote:

···

On 7/9/05, scott <scott@ebbyfish.com> wrote:

Hello,
I am trying to preform a relative import of a variable like this:

import ..common.filename as common

The file common.py is two levels above the file that is needing the
filename variable.

I haven't tried this as of yet but I thought it was possible...

Can any tell be the correct way to import parent modules?

thanks
Scott

You can load a file directly, bypassing the normal import mechanism,
using the methods in the imp module.

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.11/44 - Release Date: 7/8/2005

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.336 / Virus Database: 267.8.12/46 - Release Date: 7/11/2005

> You can load a file directly, bypassing the normal import mechanism,
> using the methods in the imp module.

How? I looked at what little was available in then doc strings, but I
can't get anything to work, just errors. :frowning:

Here's a quick sample that works for me (I created an empty directory
beneath my app directory and ran this from with it):

import imp
f = open("..\ids.py")
ids = imp.load_module("ids", f, f.name, ('py, 'r', imp.PY_SOURCE))
help(ids)

Note that doing this sort of low level stuff loses you a lot of the
built in simplicity and functionality. Refactoring so you don't have
to do it may be a better idea.

···

On 7/11/05, scott <scott@ebbyfish.com> wrote:

Scott

Chris Mellon wrote:
> On 7/9/05, scott <scott@ebbyfish.com> wrote:
>
>>Hello,
>>I am trying to preform a relative import of a variable like this:
>>
>>import ..common.filename as common
>>
>>The file common.py is two levels above the file that is needing the
>>filename variable.
>>
>>I haven't tried this as of yet but I thought it was possible...
>>
>>Can any tell be the correct way to import parent modules?
>>
>>thanks
>>Scott
>>
>>
>
>
> You can load a file directly, bypassing the normal import mechanism,
> using the methods in the imp module.
>
>
>>--
>>No virus found in this outgoing message.
>>Checked by AVG Anti-Virus.
>>Version: 7.0.323 / Virus Database: 267.8.11/44 - Release Date: 7/8/2005
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
>>For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>
>

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.336 / Virus Database: 267.8.12/46 - Release Date: 7/11/2005

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org