class IO:
supported_srcs = ['console', 'file']
def hidden_func():
supported_srcs.append('internet')
hidden_func()
print(supported_srcs)
It raises NameError: : name ‘supported_srcs’ is not defined
I’m trying to use a hidden function in class, but the function couldn’t access the local variable of that class.
Isn’t the scope of the class enclosing to the function?
My understanding is that Python executes the definition of class automatically and sets up a local variable namespace for that class.
New contributor
yin zeng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.