[Tutor] beginning to code
Marko Rauhamaa
marko at pacujo.net
Fri Sep 22 08:26:39 EDT 2017
Chris Angelico <rosuav at gmail.com>:
> Sure, let me just put that into a function. CPython 3.7, although I'm
> pretty sure most CPython versions will do the same, as will several of
> the other Pythons.
> [demonstration that it didn't work]
Ok. The reason is this:
Note: The contents of this dictionary should not be modified; changes
may not affect the values of local and free variables used by the
interpreter.
<URL: https://docs.python.org/3/library/functions.html#locals>
So the language specification explicitly ruled it out, unfortunately.
> (Side point: Your slot_ref function is rather bizarre. It's a closure
> AND a class, just in case one of them isn't sufficient.
I don't see anything bizarre in it at all. I use the pattern all the
time. It's called an inner class:
In Python, it is possible to nest a class within another class,
method or function.
<URL: https://en.wikipedia.org/wiki/Inner_class#Programming_languages>
Marko
More information about the Python-list
mailing list