Home  >  Q&A  >  body text

python 函数内返回list 获取结果异常

下面的方法在函数内部向list添加dict元素,然后返回,函数内打印的值结果正常,函数外部打印的值,只有list的第一个元素,请问这是内存被回收了嘛?


def get_invoke_all_methods(method_content, var_name):
    invoke_infos = []
    results = re.findall("invoke-(.*?)\n", method_content)
    if results:
        for result in results:
            result = str(result).strip()
            class_name = result[result.find(", L") + 3:result.rfind(";->")]
            method_name = result[result.find("->") + 2:]
            info = {"class_name":class_name, "method_name":method_name}
            if info not in invoke_infos:
                invoke_infos.append(info)
            info = None
                
    results = re.findall("get-object(.*?)\n", method_content)
    if results:
        for result in results:
            result = str(result).strip()
            if var_name in result:
                class_name = result[result.find(", L") + 3:result.rfind(";->")]
                method_name = result[result.find("->") + 2:]
                info = {"class_name":class_name, "method_name":method_name}
                if info not in invoke_infos:
                    invoke_infos.append(info)
                info = None                
        
    for invoke in invoke_infos:
        print "method inner:" + str(invoke) 在这里打印的值正常
           
    return invoke_infos
    
函数外部调用
invoke_infos = get_invoke_all_methods(method_content, varname)
if invoke_infos:
for invoke_info in invoke_infos:   
     print "?????" + str(invoke_info) 在这里打印的值只有list的第一个
    
    
高洛峰高洛峰2765 days ago729

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 17:57:49

    I know the problem, the above code is normal

    reply
    0
  • Cancelreply