【问题标题】:Python: RuntimeError: maximum recursion depth exceededPython:RuntimeError:超出最大递归深度
【发布时间】:2014-06-18 16:06:30
【问题描述】:

我正在尝试通读文本文件的行以拆分和提取 # 符号之间的字符串。当我运行我的代码时,我收到了错误

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

【问题讨论】:

    标签: python recursion runtime-error


    【解决方案1】:

    您需要在函数体中使用line 而不是eachLine。我用样本resultFile(几行# x # y # z #)进行了快速测试,更改后没有出现错误。

    【讨论】:

      猜你喜欢
      • 2013-12-01
      • 2017-03-24
      • 2011-12-31
      • 2017-08-09
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多