Python:运行时错误:超出最大递归深度
我正在尝试读取一个文本文件中的每一行,目的是提取那些在#符号之间的字符串。当我运行我的代码时,出现了一个错误。
RuntimeError: maximum recursion depth exceeded
下面是我的代码,任何帮助都将非常感谢!谢谢!
#function
def parameterPull(line):
if line.count('#') > 0:
temp = eachLine.split('#',1)[1]
temp2 = temp.split('#',1)[0]
temp3 = temp.split('#',1)[1]
#write these scripts to a file
parameterFile.write('\n'+temp2+'\n')
#check for multiple instance on the same line
if temp3.count('#') > 0:
parameterPull(temp3)
#make replacements
for eachLine in resultFile:
parameterPull(eachLine)
parameterFile.close()
1 个回答
1
你在函数里面需要用line
,而不是eachLine
。我做了个简单的测试,用了一个样本resultFile
(里面有几行# x # y # z #
),在做了这个修改后没有出现任何错误。