Strange varargs issue

Diez B. Roggisch deets at nospam.web.de
Fri Jan 4 08:50:59 EST 2008


Mike schrieb:
> I'm not sure if this is a bug or if I'm just not understanding
> something correctly.  I'm running the following (broken.py) on
> ActivePython 2.5.1.1, based on Python 2.5.1 (r251:54863 5/1/2007) as
> "python broken.py foo" (on Windows, of course):
> 
> 
> #!/bin/env python
> 
> import sys
> 
> class foobar(object):
>     def func(arg):
>         print 'foobar.func: %r' % arg

This needs to be

def func(self, arg):
     ....


And then of course for aclling, you need an instance of foobar as first 
argument. Either explicit, or implicit:

unbound_m = foobar.func
unbound_m(some_foobar, arg)

bound_m = foobar().func
bound_m(arg)

Or you do

@classmethod
def func(cls, arg):
     ...


Then you only need one argument, but beware: it's a classmethod, not an 
instancemethod anymore.

Diez
Diez



More information about the Python-list mailing list