为什么我的变量没有值? [重复]

问题描述 投票:-1回答:1
def findComponent(tree, component):
    for key, value in tree.items():
        if isinstance(value, dict):
            if key == component:
                componentDict = dumps({component: deepcopy(value)})
!!!!!!          print(componentDict)
!!!!!!          return componentDict
            findComponent(value, component)
        else:
            if key == component:
                componentDict = dumps({component: value})
                print(componentDict)
                return componentDict

def main():
    args = setupArgparse()
    if args.uid and args.component:
        res = get('http://localhost:5000/rest/firmware/' + args.uid).json()
        test = findComponent(res, args.component)
!!!!!!  print(test)
    else:
        res = get('http://localhost:5000/rest/firmware').json()
        print(findComponent(res, "uids"))


if __name__ == '__main__':
    main()

我的问题在于这两行。我的打印可以打印正确的json,但是当我返回它并想再次在我的主屏幕中打印时,它会打印“无”]

python printing return
1个回答
0
投票

在此行:

© www.soinside.com 2019 - 2024. All rights reserved.