vae*_*r-k 15 python coroutine python-3.x
我正在使用Python 3.5,根据PEP 492应该可以访问async with语法,但是当我尝试使用它时,我得到了一个SyntaxError.我究竟做错了什么?
In [14]: sys.version
Out[14]: '3.5.2 (default, Oct 11 2016, 04:59:56) \n[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]'
In [15]: async with aiohttp.ClientSession() as session:
File "<ipython-input-15-9799c5ce74cf>", line 1
async with aiohttp.ClientSession() as session:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
sob*_*evn 27
async with没有async功能就不能使用.正如文档所说:
在异步def函数之外使用async是一个SyntaxError.
但是这段代码可以工作:
async def some_function():
async with aiohttp.ClientSession() as session:
pass
Run Code Online (Sandbox Code Playgroud)
或者查看文档中的示例.
| 归档时间: |
|
| 查看次数: |
9604 次 |
| 最近记录: |