I am experiencing an obscure (to me) effect of dundered scoping, and trying to work out the rule for it:
#!/usr/bin/env python3
stuff = "the things"
__MORE_STUFF = "even more"
class Thing:
def __init__(self):
global __MORE_STUFF # doesn't help
print(stuff) # is OK
print(__MORE_STUFF) # fail!
Thing()
results in
$ python3 dunder.py
the things
Traceback (most recent call last):
File "dunder.py", line 12, in <module>
Thing()
File "dunder.py", line 10, in __init__
print(__MORE_STUFF) # fail!
NameError: name '_Thing__MORE_STUFF' is not defined
What is supposed to be a module-global variable is being treated as a class-level property - which, being undefined, is flagged as being undefined.
I've been trying to look through the documentation for this, but I cannot seem to work out what the rule is.
Can anyone point me to the appropriate documentation?