python classes/file structure

Terry Hancock hancock at anansispaceworks.com
Sat Apr 23 00:35:25 EDT 2005


On Thursday 21 April 2005 08:48 am, codecraig wrote:
> widget = gui.MyCustomWidget.MyCustomWidge()
> 
> ...seems weird, how should I structure this?  Is it not common to have
> one class in a .py?

No, it isn't really. Usually, there will be several related classes in a single
module.  Only if the classes get really large would I bother to separate
them out into separate files.  "One class per module" is perlthink. ;-)

Someone has already mentioned using __init__.py to control how your
classes are assembled into the package namespace.

You should also be aware that:

from gui.MyCustomWidget import MyCustomWidget

is a pretty common idiom too.

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list