1
我正在处理一个不起作用的脚本。无法理解python错误
首先我抄写错误:
File "/home/path", line nº, in out_to_mop_let #~this is the function
for lindex in range(lstart+ 4,lfinish):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
的脚本是下面的一个,在那里我已经把周围的明显的问题**符号:
def out_to_mop_let (namefilein, namefileout, keywords=""):
print namefilein
filein=open(namefilein, "r")
fileout=open(namefileout, "w")
lines = filein.readlines()
filein.close()
lstart = None
lfinish = None
for lindex in range(0,len(lines)):
if lindex-4>lstart and lines[lindex]=='\n' and lfinish==None and lstart!=None:
lfinish=lindex+1
if "CURRENT VALUE OF HEAT OF FORMATION" in lines[lindex]:
lstart=lindex
print lstart
print lfinish
fileout.write(keywords + "\n\n\n")
**for lindex in range(lstart+ 4,lfinish):
fileout.write(lines[lindex])**
fileout.close()
filein.close()
有什么错吗?
你用'None'初始化'lstart'。现在,如果''CURRENT VALUE OF HEAT OF FORMATION''不在'lines [lindex]'中,那么这个值永远不会改变。 – Matthias
如果'len(lines)== 0',那么你将永远不会进入你的循环,并且永远不会将'lstart'从'None'改变为 –
当lstart到达for循环时它看起来仍然是None,它尝试使用'+'运算符来加入'None'类型和'int' – CiaranWelsh