[Chicago] Fun at Pumping Station last Wednesday night.

Daniel Uber djuber at gmail.com
Mon May 25 19:37:33 CEST 2015

Hi Douglas,

On 5/25/15 3:15 AM, Lewit, Douglas wrote:> Hi guys,
>  I'm still confused
> why */next("name of generator")/* is better than */"name of
> generator".__next__( )/*  I mean.... they do the same thing!

I would say that in almost every case, functions that have the double
underscore starting and ending their name are private, and generally
support a public api with clearer names. Like integer.__add__() or
list.__getitem__(). There are times when you might need to pass these as
arguments, but it's probably bad style to use these directly instead of
+ and []. For generators, a similar supporting (function, language
feature) pair exists. next(name of generator) is the language feature,
like inline addition, and is preferred for reasons of style, although it
is equivalent in function to the underlying __next__ function. Calling
the private API directly is bad style (someone thought out how to
represent this in the public api). But that might be my own
misinterpretation of python culture. PEP8 says if it's documented, it's
public, but that double underscore names are 'magic', and all examples
given there exist to support language features.


Documented interfaces are considered public, unless the documentation
explicitly declares them to be provisional or internal interfaces exempt
from the usual backwards compatibility guarantees. All undocumented
interfaces should be assumed to be internal.

https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles :

__double_leading_and_trailing_underscore__ : "magic" objects or
attributes that live in user-controlled namespaces. E.g. __init__ ,
__import__ or __file__ . Never invent such names; only use them as

More information about the Chicago mailing list