Project layout / Import files from different subdirectories
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Nov 15 03:02:17 EST 2008
En Tue, 11 Nov 2008 09:29:44 -0200, Stef Mientki <stef.mientki at gmail.com>
escribió:
> On Tue, Nov 11, 2008 at 8:46 AM, Markus Mayer <code at organisati.on> wrote:
>
>> I'm new to python and have a slight problem importing - or maybe
>> understanding - modules. I'm writing a GUI application using Qt4 and
>> wanted to separate the business from the view logic. So I have my folder
>> structure as following:
>>
>> project/ main.py
>> important.py
>>
>> project/ gui/ __init__.py
>> mainwindow.py
>> anotherwindow.py
>>
>> Now I can import mainwindow etc. from main and important, but how do I
>> do it the other way round?
>>
>> Also, is there maybe a better project layout? I couldn't find anything
>> useful on it asking Dr. Google.
>
>
> Since a couple of days,
(good to know it's not a long established practice!)
> I use this construct and it seems to work quite well,
> http://mientki.ruhosting.nl/data_www/pylab_works/pw_importing.html
uhm... I don't think extending sys.path to include every package is a good
idea. You're basically flattening the directory structure. Just put all
your stuff in a single directory if this is what you want -- if that's not
what you want, it is what you are actually doing, anyway.
Among other nasty things, you may end up having multiple copies of the
same module, when imported using different names.
--
Gabriel Genellina
More information about the Python-list
mailing list