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