New submission from Jeff Zhang: I want to use pickle in compile/exec, but it doesn't work for me. It only works when I use the global namespace. But I don't want to use global namespace, is there any way for that ? Thanks
>>> a = compile("def f():\n\t'hello'\nimport pickle\npickle.dumps(f)", >>> "<stdin>", "exec") >>> exec(a) # works >>> exec(a, {}) # fails Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 4, in <module> _pickle.PicklingError: Can't pickle <function f at 0x1050881e0>: it's not the same object as __main__.f >>> exec(a, {'__name__': '__main__'}) # fails too Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 4, in <module> _pickle.PicklingError: Can't pickle <function f at 0x1050882f0>: it's not the same object as __main__.f ---------- components: Library (Lib) messages: 293032 nosy: Jeff Zhang priority: normal severity: normal status: open title: pickle doesn't work in compile/exec type: enhancement versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30275> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com