class attrdict
Alex Martelli
aleax at mac.com
Sun Mar 4 10:54:23 EST 2007
goodwolf <Robert.Katic at gmail.com> wrote:
...
> Then you will prefer something like this:
>
> class Namespace(object):
> def __init__(self, __ns={}, **kwargs):
> if kwargs: __ns.update(kwargs)
> self.__dict__ = __ns
I might, if it weren't for the redundant "if" and the horribly buggy
interference between separate instances -- which is why I wrote it,
almost six years ago and without the bugs, as
<http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52308> .
Not much later, in the printed Cookbook, I also gave some other good
ways and explained (as I did in the current thread) why confusing
attributes and items, as proposed in most of this thread, is really a
bad idea.
Alex
More information about the Python-list
mailing list