Defining class files
John J. Lee
phrxy at csv.warwick.ac.uk
Thu Mar 29 12:44:19 EST 2001
On Wed, 28 Mar 2001, Neil Benn wrote:
[...]
> >>> YourClass
> <module YourClass at 2584541>
>
> The text file is saved as YourClass.py - is this the problem, should
> class files have different terminaters in their filename??
[...]
The module name comes from the name of the file it is saved in.
YourClass.py gives you a module called YourClass. This is fine -- using
the same name for both class and module is common practice (although not
when the module name includes the word 'class'!) -- but you'll have to
use:
import YourClass
foo = YourClass.YourClass()
or this:
from YourClass import YourClass
foo = YourClass()
to get at the class inside the module.
John
More information about the Python-list
mailing list