文件里已存在列表,想在这个列表里再添加元素,不知道怎么实现。
代码如下:
import pickle
mylist2 = []
a = input("请输入:")
with open('mylist.txt', 'wb') as f:
pickle.dump(mylist2, f)
with open('./data/texT.txt', 'rb') as f:
mylist2 = pickle.load(f)
mylist2.append(a)
with open('mylist.txt', 'wb') as f:
pickle.dump(mylist2, f)
with open('./data/texT.txt', 'rb') as f:
mylist1 = pickle.load(f)
print(mylist1)