我如何将这个json.dumps()传递给函数使用?

时间:2019-02-20 01:04:09

标签: python

如何将结果传递给display_function?

def some_function ():
    url = "someurl"
    data = requests.get(url).json()
    result = json.dumps(data)
    display_function(result)

def display_function (result): ## get's json.dumps(data) to use and display to html in this function
    output = "some html goes here:" + result 
    return output

1 个答案:

答案 0 :(得分:1)

您仅定义函数,但从未真正调用它们。您可以尝试像这样重写脚本:

joe

您还可以通过以下调整来测试它是否通过:

def some_function ():
    url = "someurl"
    data = requests.get(url).json()
    result = json.dumps(data)
    main_result = display_function(result)
    return main_result

def display_function (result): ## get's json.dumps(data) to use and display to html in this function
    output = "some html goes here:" + result 
    return output

if __name__ == "__main__":
    my_results_wanted = somefunction()