大家好,我有一段脚本:
global auth, username, password, index, authType, rotation # Frist try - doesn't work
auth, username, password, index, authType, rotation = None # Second try - doesn't work either
@app.route("/set", methods=["GET","POST"])
def setup():
auth = request.args.get("auth", type=str)
username = request.args.get("username", type=str)
password = request.args.get("password", type=str)
index = request.args.get("index")
authType = request.args.get("type", type=str)
rotation = request.args.get("rotation", type=str)
print(authType)
return anotherMethod()
def anotherMethod():
#Do something here with authThype mentioned above.
return "succes"
在本例中,authType get是一个未定义的错误。此外,我尝试将上面的所有变量设置为“None”,并删除了“global”声明,因为我希望在一个请求中获取它们,然后将它们处理到其他方法中,而不将它们作为方法变量发送,但这些方法都不起作用
关于如何处理通过api调用发送到同一.py文件的其他方法的变量,你们有好的想法吗
您不需要使用全局变量
request.args.get()
默认为string,因此不需要这样做。尝试以下方法进行诊断:编辑:
如果你坚持使用globals。您需要在函数中声明它们(如果您想在那里更改它们):
另一种解决方案:
不确定为什么不希望将值作为方法变量传递,但这可能符合您的要求。嵌套函数:
相关问题 更多 >
编程相关推荐