0

I have first created a file using wb mode and dumped a string 'Hi guys'. Now I opened the same file again with ab mode and appended another string 'bye guys'.

Finally when I open it in rb mode and load the file, the appended string is missing. It only loads 'Hi guys'.

But when I load it twice, I get 'Hi guys' and 'bye guys' as two separate outputs.

import pickle as p

f1 = open('rough1bin.dat', 'wb')
p.dump('Hi guys', f1)
f1.flush()
f1.close()

f2 = open('rough1bin.dat', 'ab')
p.dump('bye guys', f2)
f2.close()

f3 = open('rough1bin.dat', 'rb')
l3 = p.load(f3)
print(l3)
f3.close()

Output:

Output

mkrieger1
  • 14,486
  • 4
  • 43
  • 54

0 Answers0