python import aiofiles async def read_file(): async with aiofiles.open('file.txt', mode='r') as file: content = await file.read() print(content) asyncio.run(read_file()) pip install aiofiles python import aiofiles import asyncio async def read_file(): async with aiofiles.open('file.txt', mode='r') as file: content = await file.read() print(content) async def write_file(): async with aiofiles.open('output.txt', mode='w') as file: await file.write('Hello, world!') async def main(): await asyncio.gather(read_file(), write_file()) asyncio.run(main())


上一篇:
下一篇:
切换中文