34_pickle.py 535 B

1234567891011121314151617181920212223242526
  1. # View more python learning tutorial on my Youtube and Youku channel!!!
  2. # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  3. # Youku video tutorial: http://i.youku.com/pythontutorial
  4. import pickle
  5. a_dict = {'da': 111, 2: [23,1,4], '23': {1:2,'d':'sad'}}
  6. # pickle a variable to a file
  7. file = open('pickle_example.pickle', 'wb')
  8. pickle.dump(a_dict, file)
  9. file.close()
  10. # reload a file to a variable
  11. with open('pickle_example.pickle', 'rb') as file:
  12. a_dict1 =pickle.load(file)
  13. print(a_dict1)