简体   繁体   English

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

[英]Python: RuntimeError: maximum recursion depth exceeded

I am trying to read through lines of a text file to split and pull strings that are between # signs. 我正在尝试通读文本文件的行以拆分和提取#号之间的字符串。 When I run my code I am getting the error 运行代码时出现错误

RuntimeError: maximum recursion depth exceeded

Here is my code below, any help would be greatly appreciated. 这是我的下面代码,任何帮助将不胜感激。 Thanks! 谢谢!

#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() 

You need line instead of eachLine in the function body. 您需要在函数主体中使用line而不是eachLine I made a quick test with a sample resultFile (several lines of # x # y # z # ) and no error occurred after making the change. 我使用示例resultFile# x # y # z #几行)进行了快速测试,进行更改后未发生错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM