Using property in classic class may not work

Christian Tanzer tanzer at swing.co.at
Tue Apr 15 09:08:38 CEST 2003


Neil Hodgson <nhodgson at eb2.net.au> wrote:

>     The "property" feature in Python 2.2 appears very helpful to me and
> seems to work on both classic and new-style classes. However, pychecker
> gives this error message:
>
> DemonTerm.py:563: Using property (frame) in classic class DemonFrame may
> not work
>
>     The class in question is derived from a wxWindows class, so I can't
> make it derive just from object. The "What's New in Python 2.2" document
> only mentions property wrt new-style clases. Can I depend on property
> working for classic classes?

>>> class T :
...   def _get_x(self) :
...     return 42 * self.i
...   x = property(_get_x)
...   def __init__(self) :
...     self.i = 5
...
>>> t = T()
>>> t.x
210
>>> t.i+=1
>>> t.x
252
>>> t.x = "foo"
>>> t.x
'foo'

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92






More information about the Python-list mailing list