[Zope-dev] __setattr__

Chris Withers chrisw@nipltd.com
Wed, 09 Aug 2000 11:21:14 +0100


Chris Withers wrote:

<snip last idea>

At Steve Alexander's suggestion, I'm going to try subclassing DataBlob
from PersistentMapping.
So now I need to add attribute support...

How do the following three methods sound:

def __getattr__(self,name):
	try:
		return PersistentMapping.__getattr__(self,name)
	except AttributeError,e:
		try:
			return self.__getitem__(name)
		except KeyError:
			raise AttributeError, e

def __setattr__(self,name,value):
	self.__setitem__(self,name,value)

def __delattr__(self,name):
	try:
		self.__delitem__(self,name)
	except KeyError,e:
		raise AttributeError,e

Can anyone see any problems?

cheers,

Chris