|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pickle
def pickles(file):
boy = []
girl = []
count = 1
for i in file:
i = i.replace('\n','')
words = i.split(':')
if words[0] == '小甲鱼':
boy.append(words[1])
if words[0] == '小客服':
girl.append(words[1])
if i[0:7] == '=======':
pickle_file_boy = open('boy_' + str(count) + '.txt','wb')
pickle.dump(boy,pickle_file_boy)
pickle_file_boy.close()
pickle_file_girl = open('girl_' + str(count) + '.txt','wb')
pickle.dump(boy,pickle_file_girl)
pickle_file_girl.close()
count += 1
boy.clear()
girl.clear()
if words[0] == '小甲鱼':
boy.append(words[1])
if words[0] == '小客服':
girl.append(words[1])
pickle_file = open('boy_' + str(count) + '.txt','wb')
pickle.dump(boy,pickle_file)
pickle_file.close()
pickle_file = open('girl_' + str(count) + '.txt','wb')
pickle.dump(boy,pickle_file)
pickle_file.close()
file_content = open('record.txt','r')
pickles(file_content)
file_name = open('boy_1.txt','rb')
list1 = pickle.load(file_name)
print(list1)
31讲课后作业,为毛打印出来的列表是这样的?
['咦??', '咦??', '。。。。。。', '。。。。。。', '然后呢?', '然后呢?', '呃。。。。。。你真牛!', '呃。。。。。。你真牛!', '下次有人想调戏你我不阻止~', '下次有人想调戏你我不阻止~'],次数变多了两倍?哪个亲爱滴鱼油告我一下,嘿嘿嘿。
。。进来发现已经改好了,没什么问题的话设个最佳答案呗
|
|