Python getattr called twice?

I use this simple example to understand the Python getattr function :

In [25]: class Foo:
   ....:     def __getattr__(self, name):
   ....:         print name
   ....:         
   ....:         

In [26]: f = Foo()

In [27]: f.bar
bar
bar

Why baris it printed twice? Using Python 2.6.5.

+3
source share
2 answers

I think this is due to IPython.

To “fix” it, you need to disable autorun: %autocall 0

This is the inevitable side effect of% autocall: since it must parse the object on the command line to see if it is callable, the python getattr triggers call it.

Source: http://mail.scipy.org/pipermail/ipython-user/2008-June/005562.html

+9
source

IPython. CPython REPL .

+3

Source: https://habr.com/ru/post/1763280/


All Articles