mirror of
https://github.com/satwikkansal/wtfpython.git
synced 2024-08-17 16:10:42 +03:00
Fix typo
getclosurevals -> getclosurevars
This commit is contained in:
parent
048a620502
commit
de4b851c72
2
README.md
vendored
2
README.md
vendored
@ -1027,7 +1027,7 @@ The values of `x` were different in every iteration prior to appending `some_fun
|
||||
* When defining a function inside a loop that uses the loop variable in its body, the loop function's closure is bound to the *variable*, not its *value*. The function looks up `x` in the surrounding context, rather than using the value of `x` at the time the function is created. So all of the functions use the latest value assigned to the variable for computation. We can see that it's using the `x` from the surrounding context (i.e. *not* a local variable) with:
|
||||
```py
|
||||
>>> import inspect
|
||||
>>> inspect.getclosurevals(funcs[0])
|
||||
>>> inspect.getclosurevars(funcs[0])
|
||||
ClosureVars(nonlocals={}, globals={'x': 6}, builtins={}, unbound=set())
|
||||
```
|
||||
Since `x` is a global value, we can change the value that the `funcs` will lookup and return by updating `x`:
|
||||
|
Loading…
Reference in New Issue
Block a user