class property not working in python 2.5.1

Christian Heimes lists at cheimes.de
Thu Feb 26 02:56:30 EST 2009


Dan Barbus schrieb:
> Hi,
> 
> I have a problem with setting a property to a class instance, in
> python 2.5.1. The property is defined through get and set methods, but
> when I set it, the setter doesn't get called. Instead, I believe the
> property in the instance gets replaced with a new object (string).
> 
> I have the following code (stripped down from my program):
> 
> class Model():
>     def __init__(self, title = ''):
>         self._views, self._title = [], None
>         self.setTitle(title)

*snip*

Properties don't work correctly on old style classes. You have to
subclass from object in order to get a new style class.

class Model(object):
    pass

Christian




More information about the Python-list mailing list