Impossible to change methods with special names of instances of new-style classes?
steve at REMOVE-THIS-cybersource.com.au
Thu Jul 10 08:55:45 CEST 2008
On Tue, 08 Jul 2008 17:56:45 -0400, Joseph Barillari wrote:
> Hi python-list,
> I've just started using new-style classes and am a bit confused as to
> why I can't seem to alter methods with special names (__call__, etc.) of
> new-style class instances.
[deploy weapon of mass snippage]
Here is a possible work-around:
>>> class Special(object):
... def __call__(self):
... return self.__dict__['__call__']()
... except KeyError:
... return 'foo'
>>> s = Special()
>>> s.__call__ = lambda: 'bar'
More information about the Python-list