How to structure packages

bclark76 bclark76 at
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:


my is blank.

my looks like:

import blah

class MyClass(blahblah):

then I have a 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, 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?


More information about the Python-list mailing list