Newbie Question: Giving names to Elements of List/Tuple/Dict
Max M
maxm at mxm.dk
Sat Nov 30 06:19:41 EST 2002
Duncan Booth wrote:
> Oren Tirosh <oren-py-l at hishome.net> wrote in news:mailman.1038579643.30978.python-list at python.org:
> Or a nearly empty class if you want to be lazier when creating
> the objects:
>
>
>>>>class Struct:
>
> def __init__(self, **args):
> vars(self).update(args)
There is a special notes in the docs warning against changing the values
that are returned from vars()
This is the more "correct" way to do it.
class Struct:
def __init__(self, **kw):
self.__dict__.update(kw)
regards Max M
More information about the Python-list
mailing list