Newbie questions part 2, thanks
Peter Hansen
peter at engcorp.com
Thu Nov 15 21:45:38 EST 2001
David Grenier wrote:
>
> (still this is in class cons)
>
> Whenever I call cons.mappe(lambda x:2*x, cons(1,[]))
> I get the folowing error.
>
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in ?
> cons.mappe(lambda x:2*x, cons(1,[]))
> TypeError: unbound method mappe() must be called with instance as first
> argument
Don't call the method on the class. Call it on an instance.
You have not created an instance of the class you defined. You
are doing this:
class A:
def func(a):
print 'here'
A.func()
instead of this:
class A:
def func(self):
print 'here'
a = A()
a.func()
If you don't understand the difference, follow Paul's advice
and go back to read the full tutorial before you try to finish
the assignment...
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list