python异步文件写入
作者:YXN-python 阅读量:91 发布日期:2024-05-30
import asyncio
import os
import aiofiles
async def main():
print("Hello")
async with aiofiles.open('a.txt', 'wb') as file:
content = b"Hello, World!"
await file.write(content) # 写入内容到文件
if os.path.isfile('a.txt'):
print('文件已创建')
print("World")
asyncio.run(main())
YXN-python
2024-05-30