【发布时间】:2022-06-15 22:18:05
【问题描述】:
我想在恰好位于该函数内的另一个函数中将 1 添加到 variable。
这是我的代码,显然我已经尝试过使用和不使用global:
async def start():
variable = 0
async def begin():
#global variable
variable += 1
await begin()
我需要一个不涉及 start() 函数之外的函数参数或全局变量的解决方案。
【问题讨论】:
-
我不熟悉使用
async,但您是否尝试过使用nonlocal而不是global? -
I would need a solution that does not involve function arguments为什么 -
这是一个回调函数。
-
没有 Tomerikoo 我没有。现在会研究一下,谢谢。
标签: python python-3.x variables asynchronous