167. Asynchronous File I/O with aiofiles
import aiofiles
import asyncio
async def write_file():
async with aiofiles.open("example.txt", mode="w") as f:
await f.write("Hello, World!")
asyncio.run(write_file())import aiofiles
import asyncio
async def read_file():
async with aiofiles.open("example.txt", mode="r") as f:
content = await f.read()
print(content)
asyncio.run(read_file())Last updated