From: Nathan Huesken on
Hi,

Is it somehow possible to import modules from *.py files in a higher
level directory?
Intuitively I would do

import ../module

but that does not work.
How does it work?

Thanks!
Nathan
From: Emile van Sebille on
On 6/25/2010 2:20 PM Nathan Huesken said...
> Hi,
>
> Is it somehow possible to import modules from *.py files in a higher
> level directory?
> Intuitively I would do
>
> import ../module
>
> but that does not work.
> How does it work?

IIRC, sys.path controls the search order. You could insert your
preferred directory:

sys.path.insert(0,"/my/import/module/path")

Emile






From: Tom Pacheco on
from .. import module
or
from ..module import foo

this is intended for use within packages.

see
http://www.python.org/dev/peps/pep-0328/

also search for
python relative import


- tom

Nathan Huesken wrote:
> Hi,
>
> Is it somehow possible to import modules from *.py files in a higher
> level directory?
> Intuitively I would do
>
> import ../module
>
> but that does not work.
> How does it work?
>
> Thanks!
> Nathan
>

From: Thomas Jollans on
On 06/26/2010 01:35 AM, Tom Pacheco wrote:
> from .. import module
> or
> from ..module import foo
>
> this is intended for use within packages.

And it only works within nested packages.

Also, please refrain from top posting.

>
> see
> http://www.python.org/dev/peps/pep-0328/
>
> also search for
> python relative import
>
>
> - tom
>
> Nathan Huesken wrote:
>> Hi,
>>
>> Is it somehow possible to import modules from *.py files in a higher
>> level directory?
>> Intuitively I would do
>>
>> import ../module
>>
>> but that does not work.
>> How does it work?
>>
>> Thanks!
>> Nathan
>>
>

From: D'Arcy J.M. Cain on
On Sat, 26 Jun 2010 11:10:06 +0200
Thomas Jollans <thomas(a)jollans.com> wrote:
> Also, please refrain from top posting.

If you are going to berate people for bad netiquette you should learn
it too. Please trim your included text. You included the entire rest
of the OP's message including his signature after your response.

--
D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.