8.3. Pickle File

  • File extension pkl

  • rb reading in binary mode

  • wb writing in binary mode

8.3.1. SetUp

>>> import pickle

8.3.2. Serialize to File

>>> DATA = [1, 2, 3]
>>>
>>> with open('/tmp/myfile.pkl', mode='wb') as file:
...     pickle.dump(DATA, file)

8.3.3. Deserialize from File

Load from file:

>>> with open('/tmp/myfile.pkl', mode='rb') as file:
...     result = pickle.load(file)
>>>
>>> print(result)
[1, 2, 3]