Hi folks,
I am trying to replace dinamically the __call__ method of an object using
setattr.
Example:
$ cat testcall.py
class A:
def __init__(self):
setattr(self, '__call__', self.newcall)
def __call__(self):
print("OLD")
def newcall(self):
print("NEW")
a=A()
a()
I expect to get "NEW" instead of "OLD", but in Python 3.4 I get "OLD".
$ python2.7 testcall.py
NEW
$ python3.4 testcall.py
OLD
I have a few questions:
- Is this an expected behavior?
- Is possible to replace __call__ dinamically in Python 3? How?
Best regards,
Roberto
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com