2008-07-01 20:14:44 |
Angelo Bonet |
description |
Python seems to call an object's __getattr__ function inconsistently and at times when regular Python does not. According to the Python documentation on __getattr__: "if the attribute is found through the normal mechanism, __getattr__() is not called."
In the following examples, myobj has a bound method named "myfunc" defined and as well as a "__getattr__" method defined.
1) "myobj.myfunc()"
In this example, IPython first calls myobj.__getattr__, before calling myfunc.
2) "myobj.myfunc ()"
Introducing white-space between "myfunc" and "()" eliminates IPython's __getattr__ call
3) "myobj.myfunc( )"
Introducing white-space between the parens "( )" eliminates IPython's __getattr__ call
4) "x = myobj.myfunc()"
In this assignment statement, IPython does not call __getattr__.
In all of the above examples, regular Python *never* calls the object's __getattr__ routine, only myfunc is called. |
IPython seems to call an object's __getattr__ function inconsistently and at times when regular Python does not. According to the Python documentation on __getattr__: "if the attribute is found through the normal mechanism, __getattr__() is not called."
In the following examples, myobj has a bound method named "myfunc" defined and as well as a "__getattr__" method defined.
1) "myobj.myfunc()"
In this example, IPython first calls myobj.__getattr__, before calling myfunc.
2) "myobj.myfunc ()"
Introducing white-space between "myfunc" and "()" eliminates IPython's __getattr__ call
3) "myobj.myfunc( )"
Introducing white-space between the parens "( )" eliminates IPython's __getattr__ call
4) "x = myobj.myfunc()"
In this assignment statement, IPython does not call __getattr__.
In all of the above examples, regular Python *never* calls the object's __getattr__ routine, only myfunc is called. |
|