为了账号安全,请及时绑定邮箱和手机立即绑定

python代码如下,报错,怎么解决?

python代码如下,报错,怎么解决?

涤非 2017-11-26 10:44:00
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>>>
查看完整描述

1 回答

已采纳
?
pardon110

TA贡献1038条经验 获得超227个赞


报错信息都告诉你了 ,第8行错误,很明显的逻辑错误。

if each_line in f[:6] != '======':

\
查看完整回答
反对 回复 2017-11-26
  • 涤非
    涤非
    谢谢!我知道,但是我是按教程写的,他的都能运行,而且没报错。麻烦你能告诉我怎么调整吗?
  • 1 回答
  • 0 关注
  • 2883 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信