property problem

Denis S. Otkidach ods at fep.ru
Thu Jul 18 10:36:31 EDT 2002


On Thu, 18 Jul 2002, Peter Maas wrote:

PM> class proptest:

You must define new-style class (subclass object) to use
descriptors.

PM>
PM>   	def __init__(self):
PM>   		self.__data = 0
PM>
PM>   	def get_data(self):
PM>   		return self.__data
PM>
PM>   	def set_data(self, value):
PM>   		self.__data = value
PM>
PM>   	data = property(get_data, set_data)
PM>
PM>   	def meth(self):
PM>   		return self.__data
PM>
PM> This is my testcode:
PM>
PM>  >>> x = proptest()
PM>  >>> x.data=234
PM>  >>> x.data
PM> 234
PM>  >>> x.meth()
PM> 0
PM>  >>> x.set_data(234)
PM>  >>> x.meth()
PM> 234
PM>
PM> Explanation:
PM>
PM> The "data" property works but a change using the property
PM> name doesn't show in meth(). If I use the access function
PM> set_data
PM> it works as expected. Is it my fault or Python's?

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]
http://diveinto.python.ru/ [ru]






More information about the Python-list mailing list