Strange varargs issue
Fredrik Lundh
fredrik at pythonware.com
Fri Jan 4 09:00:44 EST 2008
Mike wrote:
> __f.func(a)
> TypeError: func() takes exactly 1 argument (2 given)
>
> How can this possibly be? The "caller" print statement obviously
> shows "a" is singular.
__f.func(a) is a method call, and methods always get the object itself
as an extra initial argument. to fix this, add "self" to the method
signature:
class foobar(object):
def func(self, arg):
print 'foobar.func: %r' % arg
see the tutorial for more info.
> I'm not sure if this is a bug or if I'm just not understanding
> something correctly.
you are aware that blaming your mistakes on bugs in widely used code is
somewhat rude, right?
http://www.catb.org/~esr/faqs/smart-questions.html#id306617
</F>
More information about the Python-list
mailing list