Ronald Oussoren <ronaldousso...@mac.com> added the comment:
I don't think this is a bug. def func(): print(var) This captures the globals at the time of definition, that is "global" references are resolved using the func.__globals__ attribute which is the globals dictionary at the time the function is created exec("func()", globals=my_globals;locals=my_globals) This runs code with a different globals dictionary, but that doesn't affect the already defined function because it resolves names with the previously captured globals dictionary. This is basically the mechanism that ensures that functions defined in a module use that modules global namespace, and not the globals from where they are called. ---------- nosy: +ronaldoussoren _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38331> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com