setting a property via self.__dict__

holger krekel pyth at
Wed Oct 30 22:02:11 CET 2002

Frank von Delft wrote:
> Duncan Booth <duncan at> wrote in message news:<Xns92B75C6BDF4Eduncanrcpcouk at>...
> > The property is an entry in the class's dictionary, not in the instance.
> Um...  after some mulling:  so what is the advantage of having the
> property in the class dictionary?  Because I realised it's quite happy
> in the instance dictionary, like such:
> >>> class A(object):
> 	def __init__(self,**kwargs):
> 		self.a = property(self._getA,self._setA)
> 		self.__dict__.update(**kwargs)
> 	def _getA(self): 
> 		return self._a
> 	def _setA(self,a):
> 		self._a = a
> Really I should ask:  why do all the examples show it defined in the
> class dictionary?

because if you put it in the instance it exists only in the instance :-)
and if you put it in the class all instances will have it. 



More information about the Python-list mailing list