[IPython-user] Properties at ipython shell

T J tjhnson@gmail....
Wed Nov 12 21:45:06 CST 2008

I am experiencing some unusual behavior *only* when I am directly
working in the ipython shell.  The problem involves the get method for
a property.

class MyClass():
    def __init__(self):
        self._x = 3
    def getx(self):
        print "getting x"
        return self._x
    def setx(x):
        print "setting x"
        self._x = x
    x = property(getx, setx)

a = MyClass()
a.x           # prints "getting x" twice
print a.x  # prints "getting x" once

If you stick all this in a file and do 'run test.py', the problem does
not occur.  Also, notice that it does not occur in the "print a.x"

Any thoughts as to why this is happening?

Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
IPython 0.9.0.bzr.r1016 -- An enhanced Interactive Python.

More information about the IPython-user mailing list