Description:
- Real asynchronous file operations with asyncio support.
Resources:
- [GitHub] https://github.com/mosquito/aiofile
Example 1
Section titled “Example 1”Create a new file asynchronously and write to it
import asynciofrom pathlib import Pathfrom tempfile import gettempdir
from aiofile import async_open
tmp_filename = Path(gettempdir()) / "hello.txt"
async def main(): async with async_open(tmp_filename, 'w+') as afp: await afp.write("Hello ") await afp.write("world") afp.seek(0)
print(await afp.read())
await afp.write("Hello from\nasync world") print(await afp.readline()) print(await afp.readline())
loop = asyncio.get_event_loop()loop.run_until_complete(main())ganymede is made by Eugo