<jupyter_start><jupyter_text>open file<jupyter_code>fileName = "pickleTest"
fileObject = open(fileName, 'wb')<jupyter_output><empty_output><jupyter_text>save object to file<jupyter_code>pickle.dump(a, fileObject)
fileObject.close()<jupyter_output><empty_output><jupyter_text>read from file<jupyter_code>fObject = open(fileName, 'rb')
type(fObject)
fileName
b = pickle.load(fObject)
fObject.close()
b

a == b<jupyter_output><empty_output><jupyter_text>easier way to handle opening and closing file<jupyter_code>with open(fileName, 'rb') as pfile:
    c = pickle.load(pfile)
c<jupyter_output><empty_output><jupyter_text>adding multiple data structures<jupyter_code>d = ['testa', 'testb', 'testb']
d
with open(fileName, 'ab') as pfile:
    pickle.dump(d, pfile)
with open(fileName, 'rb') as pfile:
    e = pickle.load(pfile)
    f = pickle.load(pfile)
e
f<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1360544217687075, 'fraction_numerical': 0.0, 'mean_word_length': 8.197916666666666, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '243147', 'license': 'MIT', 'n_tokens_mistral': 351, 'n_tokens_neox': 356, 'n_words': 62, 'path': 'jupyter/pickle.ipynb', 'repo_name': 'ayushmaskey/ayushmaskey.github.io', 'size': '882'}