The following works: Ok, that is, does not give any errors:
def foo(arg): class Nested(object): x = arg foo('hello')
But the following throws an exception:
def foo(arg): class Nested(object): arg = arg
Traceback:
Traceback (most recent call last): File "test.py", line 6, in <module> foo('hello') File "test.py", line 3, in foo class Nested(object): File "test.py", line 4, in Nested arg = arg NameError: name 'arg' is not defined
I can not understand the reason for this behavior. Can someone explain?
source share