【发布时间】:2021-11-29 03:19:12
【问题描述】:
我有以下函数,我将输出存储到一个名为 post 的变量中。
jobs = ('Cook', 'Vet', 'Doctor', 'Pilot')
def careers():
output_of_careers = "Heres a list of jobs\n\n"
for j in jobs:
output_of_careers += f"This person is a {j}.\n"
output_of_careers += "\nAre you interested in any of these as careers?"
return output_of_careers
post = careers()
我需要将它传递给另一个名为(例如)apicall的函数
apicall(argument1,argument2,post)
最终发生的事情是我得到None 作为函数中post 参数的响应,即使我使用print(post) 或print(careers())。
我需要让post 显示函数careers() 的以下输出
Heres a list of jobs
This person is a Cook.
This person is a Vet.
This person is a Doctor.
This person is a Pilot.
Are you interested in any of these as careers?
在 Python 中完成此任务的正确方法是什么?谢谢
编辑添加apicall()函数供参考
def apicall(arugment1,arugment2,post):
apikey = 'Key here'
headers = {'X-API-Key' : apikey}
uri = 'urihere'
# Set Query
query = 'mutation {windowUpdate(guid: "' + arugment1 + '", window: {id: "' + arugment2 +'", configuration: {combobox: {text: "' + str(post) + '"}}, {errors {description}}}'
response = requests.post(uri, headers = headers, data=query)
print(response)
【问题讨论】:
-
你能指定
apicall函数的调用位置吗? -
你必须在函数中传递
jobs才能在循环中使用 -
我认为您应该在
requests.post()之前添加print(query)以查看最终查询的样子。 -
@MelvinAbraham 我已添加该功能以供参考。我需要 apicall 函数中的 post 参数以上面打印的格式显示函数 careers() 的输出。谢谢!