Skip to content

Instantly share code, notes, and snippets.

@CosineP
Created November 29, 2018 21:29
Show Gist options
  • Save CosineP/38c88184358a3390e94845eee82b2be0 to your computer and use it in GitHub Desktop.
Save CosineP/38c88184358a3390e94845eee82b2be0 to your computer and use it in GitHub Desktop.
pickling memory works appropriately, keeping references in-tact
# pickling memory works appropriately, keeping references in-tact
import pickle
heap = ['original']
to_pickle = {'one': heap, 'two': heap}
s = pickle.dumps(to_pickle)
from_pickle = pickle.loads(s)
from_pickle['one'][0] = 'changed'
# outputs 'changed should be "changed"'
print(from_pickle['two'][0], 'should be "changed"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment