python classes/file structure

Steve Holden steve at holdenweb.com
Thu Apr 21 11:21:40 EDT 2005


codecraig wrote:
> What is the best/common way to structure ur python code for an
> application?
> 
> For example...if I create some custom GUI widgets I have this
> 
> C:\stuff
>     --> gui
>         --: MyCustomWidget.py
>     --: TestWidgets.py
> 
> so MyCustomWidget.py has one class, class MyCustomWidget: ...
> 
> so from TestWidgets.py i have to do this
> 
> from gui import *
> 
> widget = gui.MyCustomWidget.MyCustomWidge()
> 
> ...seems weird, how should I structure this?  Is it not common to have
> one class in a .py?
> 
> thanks
> 
gui/__init__.py should import MyCustomWidget. Then

from gui import *

will inject the "MyCustomWidget" name into the namespace of the 
TestWidgets module along with all other names defined by gui/__init__.py 
- you can control this by putting the names as strings in the "__all__" 
variable in __init__.py.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list