Message369595
> as it's either the
variable should exist and have a value or it should be unknown and result
in NameError at this point.
One thing is the symbol and another thing is its value. The function is always aware of the existence of the symbol. For instance:
def f(x):
del x
print(x)
>>> print(f.__code__.co_varnames)
('x',)
But when the function tries to use it, it has no value associated to it because del x removed it, so it emits an UnboundLocalError because there is no value.
raceback (most recent call last):
File "lel.py", line 7, in <module>
f(3)
File "lel.py", line 3, in f
print(x)
UnboundLocalError: local variable 'x' referenced before assignment
A NameError will occur if the symbol is unknown to the function. |
|
Date |
User |
Action |
Args |
2020-05-22 11:19:51 | pablogsal | set | recipients:
+ pablogsal, Mark.Shannon, oleksandr.suvorov |
2020-05-22 11:19:51 | pablogsal | set | messageid: <1590146391.91.0.455497428218.issue40728@roundup.psfhosted.org> |
2020-05-22 11:19:51 | pablogsal | link | issue40728 messages |
2020-05-22 11:19:51 | pablogsal | create | |
|