【问题标题】:Access a variable from a function in a function within the first从函数中的第一个函数中访问一个变量
【发布时间】: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


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-24
  • 2022-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
相关资源
最近更新 更多