Advertisement
lessientelrunya

pickle

Apr 7th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # pickle.dumps takes an object as a parameter and returns a string representation (dumps is short for “dump string”):
  2. >>> import pickle
  3. >>> t = [1, 2, 3]
  4. >>> pickle.dumps(t)
  5. '(lp0\nI1\naI2\naI3\na.'
  6.  
  7. # The format isn’t obvious to human readers; it is meant to be easy for pickle to interpret.
  8. # pickle.loads (“load string”) reconstitutes the object:
  9. >>> t1 = [1, 2, 3]
  10. >>> s = pickle.dumps(t1)
  11. >>> t2 = pickle.loads(s)
  12. >>> print t2
  13. [1, 2, 3]
  14.  
  15. # Although the new object has the same value as the old, it is not the same object:
  16. >>> t1 == t2
  17. True
  18. >>> t1 is t2
  19. False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement