__init__ is the initialiser

Roy Smith roy at panix.com
Sat Feb 1 09:40:43 EST 2014


In article <mailman.6275.1391257695.18130.python-list at python.org>,
 Ned Batchelder <ned at nedbatchelder.com> wrote:

> The existence of __new__ is an 
> advanced topic that many programmers never encounter.  Taking a quick 
> scan through some large projects (Django, edX, SQLAlchemy, mako), the 
> ratio of __new__ implementations to __init__ implementations ranges from 
> 0% to 1.5%, which falls into "rare" territory for me. 

>From our own codebase:

$ find . -name '*.py' | xargs grep 'def.*__new__' | wc -l
1
$ find . -name '*.py' | xargs grep 'def.*__init__' | wc -l
228

Doing the same searches over all the .py files in our virtualenv, I get 
2830 (__init__) vs. 50 (__new__).



More information about the Python-list mailing list