Project layout / Import files from different subdirectories

Diez B. Roggisch deets at nospam.web.de
Tue Nov 11 03:28:43 EST 2008


Markus Mayer schrieb:
> Hi folks.
> 
> 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?
> 

By placing a __init__.py into project, and then

import project.main
import project.gui.mainwindow


Diez



More information about the Python-list mailing list