python import asyncio import aiofiles async def read_file(): async with aiofiles.open('data.txt', mode='r') as f: data = await f.read() print(data) async def write_file(): async with aiofiles.open('output.txt', mode='w') as f: await f.write('Hello, async file operations!') async def main(): await asyncio.gather(read_file(), write_file()) loop = asyncio.get_event_loop() loop.run_until_complete(main())


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