📜  腌制列表 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:21.457000             🧑  作者: Mango

代码示例1
import pickle
mylist = ['I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.', "Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it?", "I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!", "No, no, 'e's uh,...he's resting."]
with open('parrot.pkl', 'wb') as f:
   pickle.dump(mylist, f)
with open('parrot.pkl', 'rb') as f:
   mynewlist = pickle.load(f)
mynewlist
output: ['I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.', "Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it?", "I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!", "No, no, 'e's uh,...he's resting."]