why __repr__ affected after __getattr__ overloaded?

Roc Zhou chowroc.z at gmail.com
Fri Jun 22 02:43:26 EDT 2007


I'm sorry but I still have a question, look at this example:
>>> class test:
...     def __init__(self):
...         self.x = 1
...     def __getattr__(self, attr_name):
...         print attr_name
...         if attr_name == 'y':
...             return 2
...         else:
...             raise AttributeError, attr_name
...
>>> t = test()
>>> t.x
1
>>> t.y
y
2
>>> print t.x
1
>>> print t
__str__
__repr__
<__main__.test instance at 0xb7f6d6cc>

Since __str__ and __repr__ does not exist because their names was
printed, why not the "AttributeError" be raised?





More information about the Python-list mailing list