[Zope] Questions about DocumentTemplate.

Mark Hammond MHammond@skippinet.com.au
Tue, 23 Mar 1999 23:00:11 +1100


> Here's an alternative that works:

Thanks for the response.

My problem is that I want a deep object model.  I want the user
to be able to say "spam.eggs" or "pantry.eggs" etc.  Just using
eggs wont do - I really need it qualified.

The solution I came up with was:

class DotWrapper:
	def __init__(self, ob):
		self._obj_ = ob
	def __getattr__(self, attr):
		bits = string.split(attr, '.')
		ob = getattr(self._obj_, bits[0])
		for bit in bits[1:]:
			ob = getattr(ob, bit)
		return ob

Then:
 s=Spam()
 print s.ss(DotWrapper(s))

does pretty-much the right thing...

Thanks,

Mark.