Pickle is used for serializing and de-serializing Python object structures.
Serialization refers to the process of converting an object in memory to a byte stream that can be stored on disk or sent over a network.
Later on, this character stream can then be retrieved and de-serialized back to a Python object.
wb : write + binaryrb : read + binaryimport pickle
dogs_dict = {'Ozzy': 3, 'Filou': 8, 'Luna': 5, 'Skippy': 10, 'Barco': 12, 'Balou': 9, 'Laika': 16 }
filename = 'dogs.txt'
# Pickling files : write data
outfile = open(filename, 'wb')
pickle.dump(dogs_dict, outfile) # object, file
outfile.close()
# Unpickling files : read data
infile = open(filename, 'rb')
new_dict = pickle.load(infile)
infile.close()
print(new_dict)
print(new_dict == dogs_dict)
참고자료
https://www.datacamp.com/community/tutorials/pickle-python-tutorial#what