'property' builtin does not work for me

Christian Heimes lists at cheimes.de
Fri May 2 17:51:13 EDT 2008


Alex Fainshtein schrieb:
> As you see, getter works properly. But when assigning to property, setter is
> not called, as I would expect. prop is simply replaced with whatever is
> assigned and ceased being a property.

properties work only for new style classes. You have to subclass your
class from object in order to get a new style class:

class Test(object):
    def getter(self):
        print "Getter called."
        return 'a'

    def setter(self, val):
        print "Setter called."

    prop = property(getter, setter)

Christian




More information about the Python-list mailing list