automatic accessors to a member var dict elements?

Alex Martelli aleaxit at
Sun Oct 17 17:13:28 CEST 2004

Jeff Shannon <jeff at> 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;-).


More information about the Python-list mailing list