setting a property via self.__dict__

holger krekel pyth at devel.trillke.net
Wed Oct 30 16:02:11 EST 2002


Frank von Delft wrote:
> Duncan Booth <duncan at rcp.co.uk> wrote in message news:<Xns92B75C6BDF4Eduncanrcpcouk at rcp.co.uk>...
> 
> > 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. 

regards,

    holger




More information about the Python-list mailing list