I'm trying to call a class member variable from within its class, but I get a NameError: name '...' is not defined.
A similar situation is created by means of the following minimum working example:
from pprint import pprint class MyClass: _my_class_variable = {'key_0': 0, 'key_1': 1} _my_keys = _my_class_variable.keys() pprint(_my_class_variable) # WORKS! pprint([value for value in _my_class_variable.values()]) # WORKS! pprint([_my_class_variable[key] for key in _my_keys]) # DOES NOT WORK! pprint([_my_class_variable[key] for key in _my_class_variable.keys()]) # DOES NOT WORK! which returns NameError: name '_my_class_variable' is not defined.
How is it possible that the first two pprint command work but not the last two pprint commands?