|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
A = open('C:\\Users\\think\\Desktop\\升学文书\\Python\\测试文件1.txt')
boy = []
girl = []
count = 1
for each_line in A:
if each_line[:5] != '=====':
(role, line_spoken) = each_line.split(':',1)
if role == 'Roger':
boy.append(line_spoken)
if role =='Shirley':
girl.append(line_spoken)
else:
file_name_boy = 'boy_' + str(count) + '.txt'
file_name_girl = 'girl_' + str(count) + '.txt'
boy_file = open(file_name_boy, 'w')
gril_file = open(file_name_girl, 'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
boy = []
girl = []
coiunt += 1
file_name_boy = 'boy_' + str(count) + '.txt'
file_name_girl = 'girl_' + str(count) + '.txt'
boy_file = open(file_name_boy, 'w')
gril_file = open(file_name_girl, 'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
A.close()
这串代码甲鱼老师上课没问题可是到了我这里就有各种各样的问题,求助各位帮忙找问题啊。。。
Traceback (most recent call last):
File "C:/Users/think/Desktop/升学文书/Python/拆分小黑记事本.py", line 21, in <module>
girl_file.writelines(girl)
NameError: name 'girl_file' is not defined
|
|