property problem
Peter Maas
peter.maas at mplusr.de
Thu Jul 18 09:44:58 EDT 2002
Hi,
while experimenting with class properties using Python 2.2.1
I encountered the following weird behaviour:
This is my testclass:
class proptest:
def __init__(self):
self.__data = 0
def get_data(self):
return self.__data
def set_data(self, value):
self.__data = value
data = property(get_data, set_data)
def meth(self):
return self.__data
This is my testcode:
>>> x = proptest()
>>> x.data=234
>>> x.data
234
>>> x.meth()
0
>>> x.set_data(234)
>>> x.meth()
234
Explanation:
The "data" property works but a change using the property
name doesn't show in meth(). If I use the access function set_data
it works as expected. Is it my fault or Python's?
Thanks for your help.
Regards,
Peter Maas
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------
More information about the Python-list
mailing list