Strange behavior of __get__ in a descriptor in IPython

Jakub Hegenbart kyosuke at kimagure.cz
Wed Nov 7 04:13:14 EST 2007


Hi,

I'm studying the descriptor protocol and its usage from the following  
document:

http://users.rcn.com/python/download/Descriptor.htm

There is some sample code:

http://users.rcn.com/python/download/Descriptor.htm#descriptor-example

that behaves in a different way on my machine than the example suggests:

In [2]: a=MyClass()

In [3]: a.x
Retrieving var "x"
Retrieving var "x"
Out[3]: 1

On the other hand, in the 'plain' Python shell, it's invoked only once as  
expected:

>>> a=desc.MyClass()
>>> a.x
Retrieving var "x"
10
>>>

Should I take as granted that IPython might in some cases access an  
attribute
of an object more than once even in face of side effects, or is this a bug?

Regards,

Jakub Hegenbart



More information about the Python-list mailing list