Alexander Belopolsky added the comment:

The SO example works for me with Python 3.5.1:

Python 3.5.1 (default, Mar  8 2016, 12:33:47)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> global_function = """
... x = "Hello World"
... def print_global_x():
...     print(x)
... print_global_x()
... """
>>> import builtins
>>> class TestEnvironment(dict):
...     def __init__(self, *args):
...         super().__init__(*args)
...
>>> global_env = TestEnvironment()
>>> global_env['__builtins__'] = builtins
>>> exec(global_function, global_env)
Hello World

btomtom5 - a bug report that consists only of an SO link is likely to be 
treated as spam by many issue tracker subscribers.  In the future, please try 
to make your reports self-contained.

----------
nosy: +belopolsky
resolution:  -> works for me
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26561>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to