Code: Select all
def test_local():
if not hasattr(test_local, "myVar"):
test_local.myVar = 10
print(test_local.myVar)
Code: Select all
>>> test_local()
10
Code: Select all
>>> test_local()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in test_local
AttributeError: 'function' object has no attribute 'myVar'
Code: Select all
>>> test_local.myVar=5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'myVar'