Заур Шибзухов wrote: > There is a syntactic sugar for item access in > dictionaries and sequences: > > o[e] = v <-> o.__setitem__(e, v) > o[e] <-> o.__getitem__(e) > > where e is an expression. > > There is no similar way for set/get attribute for objects. > If e is a given name, then > > o.e = v <-> o.__setattr__(e, v) > o.e <-> o.__getattr__(e) > > Anybody thought about this issue?
How about inheriting the dict class, something like this... >>> class C(dict): ... pass ... >>> e = 'myAttribute' >>> v = 'syntactic sugar' >>> o = C() >>> o[e] = v >>> o[e] 'syntactic sugar' -- http://mail.python.org/mailman/listinfo/python-list