[Tutor] Importing modules/classes
Hans Dushanthakumar
Hans.Dushanthakumar at navman.com
Thu Aug 25 02:02:05 CEST 2005
Hi
Am trying to get my head around classes in python.
I have a file dummy_class.py with a class definition in it, as foloows
class dummy_class:
def __init__(self):
print "__init__"
def run(self):
print "run"
Now, I have another file test_dummy.py, which only has the foll 2 lines
import dummy_class
d=dummy_class()
When I run this file (via IDLE), I get the foll error:
Traceback (most recent call last):
File "H:/Docs/PyScripts/test_dummy_class.py", line 3, in -toplevel-
d=dummy_class()
TypeError: 'module' object is not callable
However, if the class definition was part of the same file
(test_dummy.py), instead of importing it, it runs as expected. Why does
this happen?
Cheers
Hans
More information about the Tutor
mailing list