[issue34483] eval() raises NameError: name '...' is not defined

Eric V. Smith report at bugs.python.org
Thu Aug 23 20:45:17 EDT 2018


Eric V. Smith <eric at trueblade.com> added the comment:

I believe you're seeing this: https://docs.python.org/3/reference/executionmodel.html#naming-and-binding

See the paragraph that starts with "Class definition blocks and arguments to exec() and eval() are special in the context of name resolution", and the example that follows it.

Basically, you're running eval() as if it were at class scope. I think (but am not positive) that this statement, from the exec() documentation, also applies to eval(): "Remember that at module level, globals and locals are the same dictionary. If exec gets two separate objects as globals and locals, the code will be executed as if it were embedded in a class definition."

If so, then eval()'s docs should reference this, too.

----------
nosy: +eric.smith

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34483>
_______________________________________


More information about the Python-bugs-list mailing list