相关疑难解决方法(0)

Python:超出了最大递归深度

我有以下递归代码,在每个节点我调用sql查询以获取属于父节点的节点.

这是错误:

Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method DictCursor.__del__ of <MySQLdb.cursors.DictCursor object at 0x879768c>> ignored

RuntimeError: maximum recursion depth exceeded while calling a Python object
Exception AttributeError: "'DictCursor' object has no attribute 'connection'" in <bound method DictCursor.__del__ of <MySQLdb.cursors.DictCursor object at 0x879776c>> ignored
Run Code Online (Sandbox Code Playgroud)

我调用以获取sql结果的方法:

def returnCategoryQuery(query, variables={}):
    cursor = db.cursor(cursors.DictCursor);
    catResults = [];
    try:
        cursor.execute(query, variables);
        for categoryRow in cursor.fetchall():
            catResults.append(categoryRow['cl_to']);
        return catResults;
    except Exception, e:
        traceback.print_exc();
Run Code Online (Sandbox Code Playgroud)

我实际上对上述方法没有任何问题,但我还是把它放在了正确的问题概述上.

递归代码:

def leaves(first, path=[]):
    if first:
        for elem in …
Run Code Online (Sandbox Code Playgroud)

python recursion max tree-traversal depth

79
推荐指数
1
解决办法
17万
查看次数

标签 统计

depth ×1

max ×1

python ×1

recursion ×1

tree-traversal ×1