Chapter 9 Tutorial for Classes Not Working
gdamjan at gmail.com
Fri Jun 30 17:00:32 CEST 2006
> class MyClass:
> "A simple example class"
> i = 12345
> def f(self):
> return 'hello world'
> From here I run:
> x = MyClass
Did you mean x = MyClass()
> xf = x.f
> while True:
> print xf()
> This gives the following error:
> Traceback (most recent call last):
> File "<stdin>", line 2, in ?
> TypeError: unbound method f() must be called with MyClass instance as
> first argument (got nothing instead)
> Please help...this is killing me!
What you are really calling is MyClass.f without any arguments.
More information about the Python-list