Redefining __call__ in an instance
Robert Ferrell
ferrell at diablotech.com
Wed Jan 21 13:13:40 EST 2004
Jason Mobarak <jmob at nospam__unm.edu> wrote in message news:<x7KdnVMXjpAPq5rdRVn-sw at comcast.com>...
> def firstFunc (s, word='up'):
> print "foo"
>
> class callNoWork(object):
> def __new__ (cls):
> cls.__call__ = firstFunc
> return object.__new__(cls)
>
> callNoWork()()
>
> # Dunno if you've read this, but it explains this:
> # http://python.org/2.2.1/descrintro.html
Thanks for the pointer. I had read this a while ago, it didn't all
sink in, and I'd forgotten about it. That was exactly the info that I
needed. In particular, it says that __call__ is a static method, so
it is not possible to define that differently for each instance.
The code above was a good reminder for me, but because __call__ is a
static method, any new instantiation redefines __call__ for all
existing instances.
Thanks for the pointer,
-robert
More information about the Python-list
mailing list