Properties

Python 2.3 introduced ``intelligent'' assignment operators, known as properties
That is, assignment may imply a function call:
x.data = mydata;     yourdata = x.data
# can be made equivalent to
x.set_data(mydata);  yourdata = x.get_data()
Construction:
class MyClass(object):   # new-style class required!
    ...
    def set_data(self, d):
        self._data = d
        <update other data structures if necessary...>

    def get_data(self):
        <perform actions if necessary...>
        return self._data

    data = property(fget=get_data, fset=set_data)

previousnexttable of contents