0
点赞
收藏
分享

微信扫一扫

Python3 异步操作文件


aiofiles支持异步文件操作。

举例:

import asyncio
import aiofiles


async def run(text):
async with aiofiles.open('urls.txt', 'a', encoding='utf-8') as f:
await f.write(text)


async def main():
for row in range(0, 100):
print(row)
await run(str(row) + '\n')

asyncio.run(main())

参考:https://github.com/Tinche/aiofiles/


举报

相关推荐

0 条评论