课后作业31讲
import pickle
def pickles(file):
boy = []
girl = []
count = 1
for i in file:
i = i.replace('\n','')
words = i.split(':')
if words == '小甲鱼':
boy.append(words)
if words == '小客服':
girl.append(words)
if i == '=======':
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 == '小甲鱼':
boy.append(words)
if words == '小客服':
girl.append(words)
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讲课后作业,为毛打印出来的列表是这样的?
['咦??', '咦??', '。。。。。。', '。。。。。。', '然后呢?', '然后呢?', '呃。。。。。。你真牛!', '呃。。。。。。你真牛!', '下次有人想调戏你我不阻止~', '下次有人想调戏你我不阻止~'],次数变多了两倍?哪个亲爱滴鱼油告我一下,嘿嘿嘿。 sb了,我知道了
重复了两次
import pickle
def pickles(file):
boy = []
girl = []
count = 1
for i in file:
i = i.replace('\n','')
words = i.split(':')
if words == '小甲鱼':
boy.append(words)
if words == '小客服':
girl.append(words)
if i == '=======':
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 == '小甲鱼':
boy.append(words)
if words == '小客服':
girl.append(words)
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) import pickle
def pickles(file):
boy = []
girl = []
count = 1
for i in file:
i = i.replace('\n','')
words = i.split(':')
if i != '=======':
if words == '小甲鱼':
boy.append(words)
if words == '小客服':
girl.append(words)
else:
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(girl,pickle_file_girl)
pickle_file_girl.close()
count += 1
boy.clear()
girl.clear()
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('girl_1.txt','rb')
list1 = pickle.load(file_name)
print(list1)
这是改好了的。。。。。。 。。进来发现已经改好了,没什么问题的话设个最佳答案呗 hziyan 发表于 2023-2-1 23:17
。。进来发现已经改好了,没什么问题的话设个最佳答案呗
哈哈哈哈哈哈哈,笑死,ok
页:
[1]