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

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to