automatic accessors to a member var dict elements?
Alex Martelli
aleaxit at yahoo.com
Sun Oct 17 11:13:28 EDT 2004
Jeff Shannon <jeff at ccvcorp.com> wrote:
...
> >>> class MyClass(object):
> ... def __init__(self):
> ... self.__dict__['m_dict'] = {'one':1, 'two':2, 'three':3}
Incidentally, I suspect
object.__setattr__(self, 'm_dict', dict(one=1, two=2, three=3))
is preferable to working on self.__dict__ overtly, when self's class is
newstyle, at least (though I think it might work with classic classes
too). It should come down to the same effect in normal cases, but might
work better if (e.g.) there's a __slots__ = ['m_dict_'] somewhere;-).
Alex
More information about the Python-list
mailing list