考虑以下示例
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)
b的输出或值是什么?
答案 0 :(得分:1)
我运行了以下代码:
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)
得到输出[1, 2, 3, 4]
。所以,我想答案是肯定的。