Is this possible in Python ?

Carel Fellinger carel.fellinger at chello.nl
Thu May 15 07:50:13 EDT 2003


On Thu, May 15, 2003 at 10:03:55AM +0200, Helmut Jarausch wrote:
...
> Given a program with assignments like
> a=b+a
> one can say either
> monitor 'a' on the left
> or
> monitor 'a' on the right.

In python2.2 and up you can encapsulate such behavior in a class:

    class C(object):
        def __init__(self, a=0):
            print "init a"
            self.set_a(a)

        def get_a(self):
            print "right-monitor-a"
            return self._a
    
        def set_a(self, value):
            print "left-monitor-a"
            self._a = value
    
        a = property(get_a, set_a, None, "monitor a")

    b = 1
    c = C()
    c.a = b + c.a


-- 
groetjes, carel





More information about the Python-list mailing list