小甲鱼第29讲
大佬们 求解答 没看明白这一个那里错了 对照小甲鱼视频弄的def save_file(boy,girl,count):
file_name_boy = '/Users/wuxiuye/Downloads/boy' + str(count) + '.txt'
file_name_girl = '/Users/wuxiuye/Downloads/girl' + str(count) + '.txt'
boy_file = open(file_name_boy,'w')
girl_file = open(file_name_girl,'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
def split_file(file_name):
f = open(file_name)
boy = []
girl = []
count = 1
for each in f:
if each[:6] != '=':
print(each[:6])
#这里进行分割
(role,line_spoken) = each.split(':')
if role == '小甲鱼':
boy.append(line_spoken)
else:
girl.append(line_spoken)
else:
save_file(boy,girl,count)
boy = []
girl = []
count += 1
f.close()
split_file('/Users/wuxiuye/Downloads/record.txt')
这一句
if each[:6] != '=':
改为
if each[:6] != '======': jackz007 发表于 2020-11-26 15:32
这一句
改为
感谢大佬 我刚发完帖子 就发现了
页:
[1]