Nested class doesn't see class scope
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Jul 5 01:40:23 EDT 2016
On Tuesday 05 July 2016 14:41, Ian Kelly wrote:
> Class definitions don't create closures like functions do. When Python
> executes a class definition, the metaclass creates a dict, and then
> the interpreter execs the class body using that dict as the locals.
> The body of class A has one locals dict, and the body of class B has a
> completely separate locals dict. The only way to share variables
> between them (prior to the class objects actually being constructed)
> is via globals.
So, like nested functions in Python before "from __future__ import
nested_scopes".
Okay, that's reasonable.
--
Steve
More information about the Python-list
mailing list