Hi all!
The following works Ok, i.e. it doesn't 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 # note that names are the same
foo('hello')
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't understand the reason of such behavior. Could anybody explain?