1

Consider the following example

import pickle
 l1 = [1,2,3,4]
 l2 = [5,6,7,8]
 with open("test.txt", "ab") as fp:   #Pickling
   pickle.dump(l1, fp)
 fp.close()

 with open("test.txt", "ab") as fp:   #Pickling
   pickle.dump(l2, fp)
 fp.close()

 with open("test.txt", "rb") as fp:   # Unpickling
   b = pickle.load(fp)

What would be the output or the value of b?

Dani Mazahreh
  • 50
  • 1
  • 1
  • 12
  • 2
    After 45s of search: Possible duplicate to https://stackoverflow.com/questions/12761991/how-to-use-append-with-pickle-in-python/12762056#12762056 – AlexNe Mar 21 '19 at 15:19
  • 2
    You could run the code and see what is the output of b. – Julia Mar 21 '19 at 15:20

1 Answers1

2

I ran the following code:

import pickle
l1 = [1,2,3,4]
l2 = [5,6,7,8]
with open("test.txt", "ab") as fp:   #Pickling
   pickle.dump(l1, fp)
fp.close()

with open("test.txt", "ab") as fp:   #Pickling
   pickle.dump(l2, fp)
fp.close()

with open("test.txt", "rb") as fp:   # Unpickling
   b = pickle.load(fp)
print(b)

And got the output [1, 2, 3, 4]. So, I guess the answer is yes.

Artemis
  • 2,553
  • 7
  • 21
  • 36