Pythonic style involves lots of lightweight classes (for me)

Andrea Griffini agriff at tin.it
Thu Dec 14 08:01:09 EST 2006


metaperl wrote:

> .... The above program started out as a list of dictionaries, but I
> like the current approach much better.

There is even a common idiom for this...

class Record(object):
     def __init__(self, **kwargs):
         self.__dict__.update(kwargs)

This way you can use

     user = Record(name="Andrea Griffini", email="agriff at tin.it")

and then access the fields using user.name syntax

HTH
Andrea



More information about the Python-list mailing list