Using Pythons pickle to save and load variables

Recently I was playing with some code that generated big dictionaries and had to manipulate these dictonaries several times. I used to save them via Pythons pandas to CSV and load them back from the CSV the next time I was using my script. Luckily I found out an easier way to deal with saving and loading variables, namely by using Pickle.

Import

import pickle

Saving

pickle.dump(variable, open(picklename, 'wb'))

Loading

pickle.load( open( picklename, "rb" ) )