Newbie questions part 2, thanks
David Grenier
grenieda at hotmail.com
Thu Nov 15 11:29:25 EST 2001
Thanks, it worked...
Now here:
def mappe(fonction, schemeliste):
if type(schemelist.cdr) is InstanceType and
schemelist.cdr.__class__==cons:
return cons(fonction(schemelist.car), cons.mappe(fonction,
schemelist.cdr))
else:
return fonction(schemelist.car)
(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
You see as I saw that error I become to believe that whenever a function
from a class as more than 1 argument, it assumes that the first argument is
of the type of the class, now it expects fonction to be of class cons but
it's just a function and gives me that error, besides, I've written my class
as some of the tutorials i've seen.
Still I'm required to put the function as the first argument, it's a
specification.
"Paul Rubin" <phr-n2001d at nightsong.com> a écrit dans le message de news:
7xzo5ojdqd.fsf at ruckus.brouhaha.com...
> "David Grenier" <grenieda at hotmail.com> writes:
> Change this:
> > while type(champ)=='instance':
>
> to:
> while isinstance(champ, cons):
>
> The problem is that type(champ) doesn't return a string, so your test
> always is false.
More information about the Python-list
mailing list