Consider:
class Foo:
a = 1
def bar():
print(a)
I expected a
to be available to the method by scoping rules: local first, then enclosing, ...
The class Foo
creates a namespace and a scope, does it not?
bar
creates a scope; isn't it enclosed by the scope of the class? There is no a
defined in the scope of bar
, so I expected it to pick up the class variable from the enclosing scope.
Evidently I'm confused about namespaces and scopes. I've tried reading up on this, but haven't been able to find definitive clarification on this particular point (self.a
works, of course).
Foo.a
instead ofa
.