__init__ is the initialiser
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat Feb 1 10:07:18 EST 2014
On 01/02/2014 14:40, Roy Smith wrote:
> 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__).
>
You could remove all 228 __init__ and still get your code to work by
scattering object attributes anywhere you like, something I believe you
can't do in C++/Java. I doubt that you could remove the single __new__
and get your code to work.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list