Thoughts on new vs traditional idioms

Raymond Hettinger python at
Sun Feb 29 22:20:45 CET 2004

[Peter Otten]
> This is the first time I've seen the init as update idiom 

That's why I made this post.  I don't think everyone knows that the
type constructor is good for copying and that __init__ can be called
on existing objects.

> this is clearly
> not a case of love at first sight. Objects cumulating data over subsequent
> calls of __init__() seems unintuitive to me.

It certainly lacks beauty.  OTOH, any uses of it are portable back to
Py2.2 and it is much faster and more memory efficient than creating a
temporary dictionary to pass to dict.update().

Also, the aesthetics can be restored by defining a synonym:

   itemupdate = dict.__init__

The important point is that the functionality is already available and
most folks don't know about it.

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

I've re-opened Bob's patch with this alternate implementation of
making both use the same code.

Raymond Hettinger

More information about the Python-list mailing list