f = open('E:\\11.11.txt')boy = []girl = []count = 1for each_line in f: if each_line in f[:6] != '======': (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 = 'boy_' + 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() boy = [] girl = [] count += 1f.close()报错内容:Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information.>>> ================================ RESTART ================================>>> Traceback (most recent call last): File "C:\Users\YIMUH\Desktop\11.26.py", line 8, in <module> if each_line in f[:6] != '======':TypeError: '_io.TextIOWrapper' object is not subscriptable>>>
添加回答
举报
0/150
提交
取消