confused about why i get a type error when i call an object's method
Duncan Smith
buzzard at urubu.freeserve.co.uk
Tue Aug 21 14:18:18 EDT 2007
pepper at rumbalski.com wrote:
> I'm confused about why i get a type error when i call an object's
> method. Here's the example code:
>
>>>>class Foo:
>
> def __init__(self):
> self.foo = []
> def foo(self):
> print "in foo!"
>
>
>
>>>>f = Foo()
>>>>dir(f)
>
> ['__doc__', '__init__', '__module__', 'foo']
>
>>>>f.foo()
>
>
> Traceback (most recent call last):
> File "<pyshell#32>", line 1, in <module>
> f.foo()
> TypeError: 'list' object is not callable
>
>
Because f.foo is a list and you're trying to call it. You need
different names for the list and the method (both self.foo above).
Duncan
More information about the Python-list
mailing list