Open allComputableThings opened 2 years ago
seconded. im currently writing code which would benefit from opening aiofiles without a context manager.
这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
for temporary workaround you can call __aenter__
directly:
import asyncio
import aiofiles
async def test():
f = await aiofiles.open('filename.txt', mode='w').__aenter__()
try:
await f.write('123') # Now works
finally:
f.close()
asyncio.run(test())
While I love context managers, the stack isn't always the the place to perform clean up. open can be used without
async with
. How can I useaiofiles.open
without it?