|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 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[0:3]:
jiayu = each[4:-1]
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[0:3]:
girl = each[4:-1]
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文件[yes/no]')
if see_pkl == 'yes':
file_name = input('请输入需要查看的pkl文件路径')
read_dialogue(file_name)
Split_dialogue()
问题:不会打印文件所有的内容,只打印第一行的
|
-
这是以上代码运行结果
|