Source code for jz_python_chest.aiofiles_example

import asyncio

import aiofiles


[docs] async def read_file(filepath): """ Asynchronous read a file """ async with aiofiles.open(filepath, mode='r') as file: content = await file.read() print(f"Content from {filepath}:") print(content)
[docs] async def main(): tasks = [read_file('file1.txt'), read_file('file2.txt')] await asyncio.gather(*tasks)
if __name__ == '__main__': asyncio.run(main())