Thoughts on new vs traditional idioms

Peter Otten __peter__ at web.de
Sun Feb 29 06:49:36 EST 2004


Raymond Hettinger wrote:

>     d = {'a':1}
>     d.__init__([('b',2), ('c',3)])   # update with an items list
>     d.__init__(d=4, e=5)             # update with keyword arguments
>     d.__init__(mydict)               # update with another dictionary

This is the first time I've seen the init as update idiom - this is clearly
not a case of love at first sight. Objects cumulating data over subsequent
calls of __init__() seems unintuitive to me.

Why isn't dict.update() enhanced to handle all three cases? You might
actually use the same implementation for both __init__() and update().

Peter



More information about the Python-list mailing list