Re: [Zope] Questions about DocumentTemplate.
23 Mar
1999
23 Mar
'99
12:40 p.m.
Mark Hammond wrote: >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 Small caveat: Since whitespaces could occur in an nested attrbute access ("a. b .x") , it's better to string them first. An alternative approach for DotWrapper's __getattr__ could be (not tested): def __getattr__(self, attr): bits = map (string.strip, string.split(attr, '.')) return reduce (getattr, bits, self._obj) Stefan
9876
Age (days ago)
9876
Last active (days ago)
0 comments
1 participants
participants (1)
-
Stefan Franke