dsaiztc
2/22/2016 - 12:56 PM

What's the pythonic way to use getters and setters? http://stackoverflow.com/questions/2627002/whats-the-pythonic-way-to-use-getters-and-set

class C(object):
    def __init__(self):
        self._x = None

    @property
    def x(self):
        """I'm the 'x' property."""
        print "getter of x called"
        return self._x

    @x.setter
    def x(self, value):
        print "setter of x called"
        self._x = value

    @x.deleter
    def x(self):
        print "deleter of x called"
        del self._x