2

I am trying to dump many dictionaries into the same pickle file. The dictionaries share the root key.

import pickle

a = {'k':'b'}
b = {'k':'c'}

f = open('tmp.pickle','ab')
pickle.dump(a,f)
pickle.dump(b,f)
f.close()

pickle.load(open('tmp.pickle','rb'))

Result:

{'k': 'b'}

I would expect:

{'k':{'a','b'}}
martineau
  • 119,623
  • 25
  • 170
  • 301
GAP
  • 91
  • 4
  • 1
    check out this question: https://stackoverflow.com/questions/12761991/how-to-use-append-with-pickle-in-python – Roni Feb 07 '19 at 09:22
  • @Roni in that question the dictionaries have a different root key – GAP Feb 07 '19 at 09:38
  • Your code is dumping two **separate** dictionaries into the pickle file, so it does not seem reasonable to expect to get a single merged version of them back when you later read the file. Also what should happen to keys & associated values they don't have in common? – martineau Feb 07 '19 at 11:38

0 Answers0