How to structure packages

bclark76 bclark76 at gmail.com
Wed Sep 7 17:56:32 CEST 2011


I'm learning python, and was playing with structuring packages.

Basically I want to have a package called mypackage that defines a
number of classes and functions.


so I create:

mypackage
    __init__.py
    myfunc.py
    MyClass.py


my __init__.py is blank.

my MyClass.py looks like:

import blah

class MyClass(blahblah):
    blah
    blah
    blah


then I have a run.py that looks like

from mypackage import MyClass


x = MyClass()


This doesn't work because MyClass is mypackage.MyClass.MyClass.
There's this MyClass module 'in the way'.


I'm trying to follow the rule that every file defines only one class.
I could define MyClass in __init__.py, but then what if I wanted to
define more classes in the mypackage package? My one class per file
rule goes out the window.

Is this rule wrongheaded, or is there another way to do this?


Thanks.




More information about the Python-list mailing list