Class initialization from a dictionary, how best?

Nick Coghlan ncoghlan at
Fri Jan 14 08:57:31 CET 2005

brianobush at wrote:
> t2 = Test(dictionary.get('a'), dictionary.get('b'),
> dictionary.get('c'))
> print t2

Try this:

t2 = Test(**dictionary)

This performs keyword argument expansion on the dictionary, matching the 
dictionary entries with the named arguments to the Test.__init__ function.


Nick Coghlan   |   ncoghlan at   |   Brisbane, Australia

More information about the Python-list mailing list