Searching a large dictionary

Rhodri James rhodri at
Thu Sep 24 02:59:28 CEST 2009

On Thu, 24 Sep 2009 01:03:26 +0100, Sean DiZazzo <half.italian at>  

> I like to perform what I call "objectify" on nested dictionary type
> stuff into classes.
> class TestPart(object):
>         def __init__(self, **kwargs):
>             for k,v in kwargs.items():
>                 setattr(self, k, v)


> It's not quite right, but you get the basic idea.  I just find it
> easier to wrap my head around structures built like this rather than
> trying to remember alot of inner/outer, index variables, etc.

So do I, but I thought that was a complexity the OP could live without.
In this case, given the desire to check specific named keys, leaving
it as a dictionary saves a call to getattr(), so objectifying it
doesn't really do much for you.

However I'd design my objects explicitly rather than automate it like
this.  While I'm sure it works perfectly well, it does rather beg for
trouble when you carry blithely on with mis-shapen data.

Rhodri James *-* Wildebeest Herder to the Masses

More information about the Python-list mailing list