[Tutor] Basic question -> How to use a class from a file?

Bernard Lebel python at bernardlebel.com
Sun Jan 2 23:43:07 CET 2005


Hello,

An easy one to start the year.

Trying to write my first class, already running into problems after 3 
lines! :-(

So have this little class:

class rt:
	def walk(self):
		print 'yeah'

So if I write this in the Python shell, instantiate rt and call walk(), 
I get the proper result. yeah gets printed.

Now let say I put this into a file. I want to import that class and use 
its methods, but this is were I get lost.

import rt
rt.walk()

Returns:
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'walk'

When I try to instantiate the class, I get an non-callable module object 
error.


Sooooo how to use a class from a file?


Thanks
Bernard



More information about the Tutor mailing list