Python asyncio.sleep语法错误
我做错了什么? 当我运行这个时Python asyncio.sleep语法错误,python,python-3.x,syntax-error,python-asyncio,Python,Python 3.x,Syntax Error,Python Asyncio,我做错了什么? 当我运行这个时 import asyncio def oneSecond(): await asyncio.sleep(1) 我明白了: File "<string>", line 3 await asyncio.sleep(1) ^ SyntaxError: invalid syntax 文件“”,第3行 等待asyncio.sleep(1) ^ SyntaxError:无效语法 使用Python3.3您在Python3.3中使
import asyncio
def oneSecond():
await asyncio.sleep(1)
我明白了:
File "<string>", line 3
await asyncio.sleep(1)
^
SyntaxError: invalid syntax
文件“”,第3行
等待asyncio.sleep(1)
^
SyntaxError:无效语法
使用Python3.3您在Python3.3中使用了
await
关键字,但它在3.5版之前尚未添加到Python中。您应该升级Python版本
您还必须将函数定义为async
:
async def oneSecond():
await asyncio.sleep(1)
哪一个Python版本?抱歉,Python 3.3在3.5.1I上的相同问题我编辑了答案,并解决了另一个问题。现在,当我等待oneSecond()时,这是一个语法错误。您必须在asyncio事件循环中启动它。