On Apr 30, 9:09 am, Дамјан Георгиевски <gdam...@gmail.com> wrote:
> I've needed an attribute accessible dict, so I created this.
> Are there any obviously stupid shortcomings?
>
> class AttrDict(dict):
>    def __getattr__(self, name):
>        try:
>            return self[name]
>        except KeyError, e:
>            raise AttributeError(e)

Have you seen Alex Martelli's Bunch class?

class Bunch:
    def __init__(self, **kwds):
        self.__dict__.update(kwds)

From http://code.activestate.com/recipes/52308/

With Alex' version, you're not overloading a commonly called method,
nor do you have to worry about the performance of the exception
handling for misses. Plus it's half as long ;)

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to