Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. data2 = []
  2. with open("AllOutputMethodsObj.txt", "rb") as f:
  3. for _ in range(pickle.load(f)):
  4. data2.append(pickle.load(f))
  5. print (str(data2))
  6.  
  7. for _ in range(pickle.load(f)):
  8. EOFError: Ran out of input
  9.  
  10. import pickle
  11. objs = dict(a=1, b=2), [3, 4], {5, 6}
  12. pickle.dump(objs, open('test.tt', 'wb'))
  13. for ob in pickle.load(open('test.tt', 'rb')):
  14. print(ob)
  15.  
  16. import pickle
  17.  
  18. with open("objects.pickle", "rb") as file:
  19. a, b, c = pickle.load(file)
  20.  
  21. with open("objects.pickle", "wb") as file:
  22. pickle.dump([a, b, c], file)
  23.  
  24. import shelve
  25.  
  26. with shelve.open('objects') as db:
  27. db['a'] = a
  28. ...
  29. db['b'] = b
  30.  
  31. with shelve.open('objects') as db:
  32. a = db['a'] # read
  33. a += 1 # modify
  34. db['a'] = a # write back
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement