几乎可以把python的对象转换为二进制的形式存放 字节流 叫pickling
将二进制形式转换为对象的过程读取 字符流 叫unpickling
>>> import pickle
>>> my_list =[123,456,‘I love you‘, [‘another list‘]]
>>> pickle_file = open(‘/home/fengjunjie/test/my_list.pkl‘,‘wb‘)
>>> pickle.dump(my_list,pickle_file)
>>> pickle_file.close()
>>> pickle_file = open(‘/home/fengjunjie/test/my_list.pkl‘,‘rb‘)
>>> my_list2 = pickle.load(pickle_file)
>>> print(my_list2)
[123, 456, ‘I love you‘, [‘another list‘]]
大量复杂的列表,存在文件中
时间: 2024-10-27 06:55:00