You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-05-05.21:20:27.135>created_at=<Date2017-05-05.00:20:05.496>labels= ['invalid', 'type-feature', 'library']
title="pickle doesn't work in compile/exec"updated_at=<Date2017-05-05.21:20:27.133>user='https://bugs.python.org/JeffZhang'
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
It won't work without the global namespace as pickle needs to be able to figure out where the function lives (the function itself doesn't get pickled, just the name of the function).
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: