Skip to content

Instantly share code, notes, and snippets.

@sidazhou
Last active January 17, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidazhou/c26b9cf98cbbaf13ecfda8baba56c28c to your computer and use it in GitHub Desktop.
Save sidazhou/c26b9cf98cbbaf13ecfda8baba56c28c to your computer and use it in GitHub Desktop.
pickling
import pickle
class Dummy:
def __init__(self,num):
self.num = num
dummy = Dummy(666)
print(dummy) # this is object pointer, not the object
stored = pickle.dumps({'my_object': dummy})
restored = pickle.loads(stored)
# this shows pickle stores the pointed object, instead of just the object pointer
print(restored)
print(restored['my_object'].num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment