Bruno Loff added the comment:
Hmm yes, some more words in the documentation might help.
Does anyone understand why it happens, though?
Specifically, note that
sum(get(i) for i in range(len(l)))
or
eval("get(0) + get(1) + get(2) + get(3)")
or
eval("sum(get(i) for i
Bruno Loff added the comment:
Hmm... OK, if I understand correctly, the evaluation procedure for a (e.g.)
list comprehension, as described in the documentation you linked in, is as
follows:
* The generator in the leftmost for expression is evaluated in the current
local scope. (doc
New submission from Bruno Loff :
Python 3.9.2 seems to be giving me some unexpected difficulty evaluating
generators inside evals. Here is the example:
```python
def func(l):
def get(i):
return l[i]
print(sum(get(i) for i in range(len(l # works as expected, prints 10