jjxx2005 发表于 2020-7-29 09:36:20

向协程函数中传递多参数的问题,谢谢

代码写成这样就报错:
import asyncio
async def hanshu1():
    a =
    b =
    return a,b
async def main(fbi,cis):
    print(fbi,cis)
t1 = asyncio.run(hanshu1())
fbi_list = t1
cis_list = t1
task1 =
task2 =
asyncio.run(asyncio.wait(task1,task2))

我想往main函数中传两个参数,如果传一个代码如下是正常的,但是传两个肯定是我写的不对,哪位高手能帮忙指点一下,谢谢
import asyncio
async def hanshu1():
    a =
    b =
    return a,b
async def main(fbi):
    print(fbi)
t1 = asyncio.run(hanshu1())
fbi_list = t1
# cis_list = t1
task1 =
asyncio.run(asyncio.wait(task1))

Twilight6 发表于 2020-7-29 09:39:24


main 函数你设置了两个参数,只传入了一个

你试试这样行不:

import asyncio
async def hanshu1():
    a =
    b =
    return a,b
async def main(fbi,cis):
    print(fbi,cis)
t1 = asyncio.run(hanshu1())
fbi_list = t1
cis_list = t1
temp = list(zip(fbi_list,cis_list))
task1 =

asyncio.run(asyncio.wait(task1))

zltzlt 发表于 2020-7-29 09:41:47

import asyncio


async def hanshu1():
    a =
    b =
    return a, b


async def main(fbi, cis):
    print(fbi, cis)


t1 = asyncio.run(hanshu1())
fbi_list = t1
cis_list = t1
task1 =
asyncio.run(asyncio.wait(task1))

jjxx2005 发表于 2020-7-29 09:52:19

Twilight6 发表于 2020-7-29 09:39
main 函数你设置了两个参数,只传入了一个

你试试这样行不:

版主您好,程序运行报错。提示如下
Traceback (most recent call last):
File "D:/code/0000000.py", line 22, in <module>
    asyncio.run(main())
TypeError: main() missing 2 required positional arguments: 'fbi' and 'cis'

jjxx2005 发表于 2020-7-29 09:52:55

zltzlt 发表于 2020-7-29 09:41


版主您好,程序运行报错,提示如下:
Traceback (most recent call last):
File "D:/code/0000000.py", line 22, in <module>
    asyncio.run(main())
TypeError: main() missing 2 required positional arguments: 'fbi' and 'cis'

zltzlt 发表于 2020-7-29 09:55:06

jjxx2005 发表于 2020-7-29 09:52
版主您好,程序运行报错,提示如下:
Traceback (most recent call last):
File "D:/code/0000000.py ...

我这里并没有报错呀,你试试直接复制下面的代码运行?

import asyncio


async def hanshu1():
    a =
    b =
    return a, b


async def main(fbi, cis):
    print(fbi, cis)


t1 = asyncio.run(hanshu1())
fbi_list = t1
cis_list = t1
task1 =
asyncio.run(asyncio.wait(task1))

Twilight6 发表于 2020-7-29 09:55:29

jjxx2005 发表于 2020-7-29 09:52
版主您好,程序运行报错。提示如下
Traceback (most recent call last):
File "D:/code/0000000.py", ...



你不是拷贝我们的代码吧,你应该拷贝错了,重新拷贝运行即可

jjxx2005 发表于 2020-7-29 09:58:23

zltzlt 发表于 2020-7-29 09:41


只能选一个最佳答案 我就按先后顺序了感谢版主解答 加分

jjxx2005 发表于 2020-7-29 09:59:28

Twilight6 发表于 2020-7-29 09:55
你不是拷贝我们的代码吧,你应该拷贝错了,重新拷贝运行即可

感谢是我拷贝错了
页: [1]
查看完整版本: 向协程函数中传递多参数的问题,谢谢