pickle读取问题
本帖最后由 qin_yin 于 2020-10-3 21:56 编辑import pickle
import os
def read_dialogue(file_name):
pickle_file = open(file_name,'rb')
dialogue = pickle.load(pickle_file)
print(dialogue)
def Split_dialogue():
dialogur_numbers = 1
if not os.path.exists('D:\\测试文件\\pkl文件'):
os.makedirs('D:\\测试文件\\pkl文件')
fishc_dialogue = open('D:\\测试文件\\record.txt')
for each in fishc_dialogue:
if '========' in each:
dialogur_numbers += 1
print(dialogur_numbers)
if '小甲鱼' in each:
jiayu = each
jiayu_save_path = 'D:\\测试文件\\pkl文件\\boy_%s.pkl' % (dialogur_numbers)
boy_pkl = open(jiayu_save_path,'ab')
pickle.dump(jiayu,boy_pkl)
boy_pkl.close()
if '小客服' in each:
girl = each
girl_save_path = 'D:\\测试文件\\pkl文件\\girl_%s.pkl' % (dialogur_numbers)
girl_pkl = open(girl_save_path,'ab')
pickle.dump(girl,girl_pkl)
girl_pkl.close()
see_pkl = input('是否是需要查看pkl文件')
if see_pkl == 'yes':
file_name = input('请输入需要查看的pkl文件路径')
read_dialogue(file_name)
Split_dialogue()
问题:不会打印文件所有的内容,只打印第一行的
问题? kylin121380 发表于 2020-10-3 21:54
问题?
不会打印文件的所有内容,只打印了第一行的内容 qin_yin 发表于 2020-10-3 21:56
不会打印文件的所有内容,只打印了第一行的内容
dump几次就要load几次,你可以一次性dump进去
页:
[1]