Properties on old-style classes actually work?

Paul Melis paul at science.uva.nl
Mon May 7 04:44:35 EDT 2007


Hello,

The python library docs read in section 2.1 
(http://docs.python.org/lib/built-in-funcs.html):

"
...

property(  	[fget[, fset[, fdel[, doc]]]])
     Return a property attribute for new-style classes (classes that 
derive from object).

...
"


But in 2.4 at least properties also seem to work for old-style classes:

class O:
	
     def __init__(self):
         self._x = 15

     def get_x(self):
         return self._x

     x = property(get_x)

o = O()
print o.x

outputs "15" as expected for the property.

Regards,
Paul



More information about the Python-list mailing list