argument checking before getattr
Chris Liechti
cliechti at gmx.net
Sat Jan 12 12:27:11 EST 2002
Benjamin Tai <bt98 at doc.ic.ac.uk> wrote in
news:3C406C31.D5ED90F6 at doc.ic.ac.uk:
[snip]
> Instead of doing (hiding) argument checking in the interface, now I am
> hoping to do some type checking in Python. The following shows what I am
> trying to achieve:
>
> class foo:
> def foo_fun(self,args):
> # do some checking on "args"
> return getattr(self._base,"foo_fun")
>
> Instead of return the correct argument, it only returns a trace of the
> following trace:
> <built-in method foo_fun of foo object at 0x80ef820>
> It doesn't work out. Why?
because getattr gives you the function object in this case.
use apply to call the function. or write self._base.foo_fun(args)
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list