python - 等待一个有 for 循环语法错误的函数

标签 python python-3.x asynchronous discord.py

我正在尝试让一个不和谐的机器人能够在用户输入“uploadAll”时上传文件夹中的所有图像。代码是:

def get_image(path):
    image_list = []
    for filename in glob.glob(path): #appends opened images from folder
        im = Image.open(filename)    #into list image_list and returns it
        image_list.append(im)
    return image_list

async def iter_image(path):          #uploads images in the list
    for i in get_image(path):
        client.send_file(discord.Object(id='SERVER_ID'),i)

@client.command(pass_context=True)
async def uploadAll(self):           #Should trigger above method
    await iter_image('PATH_TO_FOLDER')

最后一个函数的结果是: TypeError:对象 NoneType 不能在“await”表达式中使用。我无法等待 iter_image 因为它有一个 for 循环。关于如何让事件循环触发 for 循环的任何解决方案?谢谢。

最佳答案

我很确定如果您在此处添加await,它应该可以工作

await client.send_file(discord.Object(id='SERVER_ID'), i)

关于python - 等待一个有 for 循环语法错误的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45990296/

相关文章:

javascript - 如何从异步调用返回响应?

python - 在 git 中使用 python sh 模块

python - 优化 python for 循环

python - 如何在双端队列被另一个线程修改的情况下存储和访问双端队列中的值?

python - 类似于 zip() 的内置函数,用 None 值从左边填充不等长度

django - 在 Travis 上运行 django unittests 时如何解决 "psycopg2.errors.UndefinedTable: relation "auth_user“不存在”

python - 尽管显式返回一维数组,但使用 scipy Optimize 进行 2 次迭代后出现 ValueError

python - 如何使用 simpledoctemplate reportlab 包将图像移动到 pdf 页面顶部?

objective-c - 为什么我的异步调用仍然阻止我与 Swift 中的 UI 元素交互?

ios - 在执行 AFNetwork 请求之前执行 UI 更改