[Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

Boris Borcic bborcic at gmail.com
Wed May 17 09:08:32 EDT 2017

Chris Angelico wrote:
> # Python
> def outer():
>     x = 0
>     def inner():
>         nonlocal x
>         x += 2
> Is it better to say "nonlocal" on everything you use than to say
> "self.x" on each use?

I've not used Python closures since nonlocal came about, but AFAIK you only need to use nonlocal if there's an 
assignment to the variable in the scope. Maybe an augmented assignment creates the same constraint but 
logically it shouldn't.

More information about the Python-ideas mailing list