Quentin Peter <qpe...@bluewin.ch> added the comment:
Maybe a note could be added to https://docs.python.org/3/library/functions.html#exec Something along the lines of: Note: If exec gets two separate objects as `globals` and `locals`, the code will not be executed as if it were embedded in a function definition. For example, any function or comprehension defined at the top level will not have access to the `locals` scope. PS: It would be nice for my usecase to have a way around this, maybe a flag in `compile` or `exec` that would produce "function code" instead of "module code". My workaround for this problem consist in wrapping my code in a function definition. I think this means https://bugs.python.org/issue41918 should be closed as well? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46153> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com