Python:RuntimeError:超出最大递归深度

时间:2014-06-18 16:06:31

标签: python recursion runtime-error

我试图通读文本文件的行来分割和拉出#符号之间的字符串。当我运行我的代码时,我收到了错误

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 个答案:

答案 0 :(得分:1)

在函数体中需要line而不是eachLine。我使用示例resultFile(几行# x # y # z #)进行了快速测试,并且在进行更改后没有发生错误。

相关问题