|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在mac os下为什么最后总是就创建了2个文档 boy1.txt,girl2.txt
而且打开里面都是空的的,不知道是哪里出错了,求助一下大家!
f = open('record.txt')
boy = []
girl = []
count = 1
for each_line in f:
if each_line[:2] != '==':
(role,line_spoken) = each_line.split(':',1)
if role == '小甲鱼':
boy.append(line_spoken)
if role == '小客服':
girl.append(line_spoken)
else:
file_name_boy = 'boy' + str(count) + '.txt'
file_name_girl = 'girl' + str(count) + '.txt'
file_boy = open(file_name_boy,'w')
file_girl = open(file_name_girl,'w')
file_boy.writelines(boy)
file_girl.writelines(girl)
girl = []
boy = []
count += 1
file_boy.close()
file_girl.close()
file_name_boy = 'boy' + str(count) + '.txt'
file_name_girl = 'girl' + str(count) + '.txt'
file_boy = open(file_name_boy,'w')
file_girl = open(file_name_girl,'w')
file_boy.writelines(boy)
file_girl.writelines(girl)
file_boy.close()
file_girl.close()
f.close()
你record.txt文件里有东西吗?
有的话发出来
没有的话其他两个文件肯定是空的啦
|
|