Dynamic variable creation from string

alex23 wuwei23 at gmail.com
Sun Dec 11 22:31:41 EST 2011


On Dec 11, 4:42 pm, Nobody <nob... at nowhere.com> wrote:
> If just you're trying to avoid getting a repetitive strain injury in your
> right-hand little finger from typing all the [''], you could turn
> the keys into object attributes, e.g.:
>
>         class DictObject:
>             def __init__(self, d):
>                 for key, value in d.iteritems():
>                     setattr(self, key, value)
>         ...
>         o = DictObject(D)
>         # use o.a, o.b, etc

I hate this kind of laziness. I'd spend at least 5 minutes trying to
work out _why_ someone felt this was necessary and then get annoyed
that it was just to avoid typing.



More information about the Python-list mailing list