'python variable scope LEGB rule
def fun():
print b
def pass_a(b):
fun()
.
pass_a(2) raise: NameError: global name 'b' is not defined.
According to LEGB rules, I thought to find b, python would go up stack frames, and found b in the enclosed scope pass_a? Please correct my understanding. Thx.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
