Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python函数不返回变量_Python_Json - Fatal编程技术网

Python函数不返回变量

Python函数不返回变量,python,json,Python,Json,我不明白为什么打印功能会打印预期的输出 但是返回,没有返回 这是我的职责 #json search function: def searchfunction(searches,query,myresults,i = 0): print('i:',i,'nr of searches',len(searches),'nr results:',len(myresults)) newresults = [] if i <= len(searches)-1:

我不明白为什么打印功能会打印预期的输出 但是返回,没有返回

这是我的职责

#json search function:
def searchfunction(searches,query,myresults,i = 0):

    print('i:',i,'nr of searches',len(searches),'nr results:',len(myresults))
    newresults = []

    if i <= len(searches)-1:
        for item in myresults:
            for key in item:
                if key == searches[i]:
                    #print(key, item[key],query.split(','))
                    if item[key] in query.split(','):
                        #print(key, item[key], query.split(','))
                        newresults.append(item)
        i += 1
        myresults = newresults
        tmp = searchfunction(searches, query, myresults, i)
    else:
        print('print result:',myresults)
        return myresults
输出:

i: 0 nr of searches 5 nr results: 448
i: 1 nr of searches 5 nr results: 132
i: 2 nr of searches 5 nr results: 66
i: 3 nr of searches 5 nr results: 18
i: 4 nr of searches 5 nr results: 9
i: 5 nr of searches 5 nr results: 1

print result: [{'id': '4', 'label': 'GFX_watching-tv-netflix_ipl5_Female 25+_catch_6', 'Base name': 'watching-tv-netflix', 'Product featured': 'ipl5', 'Master Messaging': 'Female 25+', 'Phase': 'catch', 'length': '6', 'Asset 1': 'copy_press-play', 'options overrides': '', 'Asset 2': 'copy_on-smooth-skin', 'Asset 3': 'endcard_long-lasting-smooth-skin-your-way', 'Asset 4': ''}]

#???
result? None

尝试了很多变体,但没有成功…

#json搜索功能:
#json search function:
def searchfunction(searches,query,myresults,i = 0):

    print('i:',i,'nr of searches',len(searches),'nr results:',len(myresults))
    newresults = []

    if i <= len(searches)-1:
        for item in myresults:
            for key in item:
                if key == searches[i]:
                    #print(key, item[key],query.split(','))
                    if item[key] in query.split(','):
                        #print(key, item[key], query.split(','))
                        newresults.append(item)
        i += 1
        myresults = newresults
        return searchfunction(searches, query, myresults, i)
    else:
        return myresults
def searchfunction(搜索、查询、myresults,i=0): 打印('i:',i,'nr of search',len(搜索),'nr results:',len(myresults)) 新结果=[]
如果我告诉你,你从未对
tmp
做过任何事情。你将内部调用的结果分配给“searchfunction”给“tmp”,但你既不返回它,也不以任何方式使用它。我尝试过删除tmp=但没有解决问题……你必须显式返回内部调用的结果。这是否回答了你的问题?
#json search function:
def searchfunction(searches,query,myresults,i = 0):

    print('i:',i,'nr of searches',len(searches),'nr results:',len(myresults))
    newresults = []

    if i <= len(searches)-1:
        for item in myresults:
            for key in item:
                if key == searches[i]:
                    #print(key, item[key],query.split(','))
                    if item[key] in query.split(','):
                        #print(key, item[key], query.split(','))
                        newresults.append(item)
        i += 1
        myresults = newresults
        return searchfunction(searches, query, myresults, i)
    else:
        return myresults