Project layout / Import files from different subdirectories

Almar Klein almar.klein at gmail.com
Tue Nov 11 08:09:33 EST 2008


If your main file is in the root of the project, you can just
use absolute imports. So you can use gui.anotherwindow
or project.important from all files.

I'm not sure this is good practice though...

I was first under the impression that you can always import
modules that are in your current working dir. But this seems
to not always work...

Almar


2008/11/11 Jeremiah Dodds <jeremiah.dodds at gmail.com>:
>
>
> On Tue, Nov 11, 2008 at 7:08 AM, Markus Mayer <code at organisati.on> wrote:
>>
>> Steve Holden schrieb:
>> > If you want shorter names in your main code, of course, you can use
>> >
>> > import project.main as main
>> > import project.gui.mainwindow as window
>> >
>> > or somethihg similar.
>> >
>> > regards
>> >  Steve
>>
>
>
> Are explicit relative imports applicable here? Could he do a
>
>     from .. import project.main as main
>
> without adding another __init__.py?
>
> Or do I have my head screwed on funny?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



More information about the Python-list mailing list