Why property works only for objects?

Michal Kwiatkowski ruby at no.spam
Fri Mar 10 04:06:26 CET 2006


Hi,

Code below shows that property() works only if you use it within a class.

------------------------------------------------
class A(object):
    pass

a = A()
a.y = 7

def method_get(self):
    return self.y

a.x = property(method_get)
print a.x # => <property object at 0xb7dc1c84>

A.x = property(method_get)
print a.x # => 7
------------------------------------------------

Is there any method of making descriptors on per-object basis? I would
like to customize x access in different objects of class A. Is this
possible and how?

mk
-- 
 . o .       >>  http://joker.linuxstuff.pl  <<
 . . o   It's easier to get forgiveness for being wrong
 o o o   than forgiveness for being right.



More information about the Python-list mailing list