def open_async(file: Union[str, Path], *args, executor: Executor = None,
**kwargs) -> AsyncFileWrapper:
"""
Open a file and wrap it in an :class:`~AsyncFileWrapper`.
Example::
async def read_file_contents(path: str) -> bytes:
async with open_async(path, 'rb') as f:
return await f.read()
The file wrapper can also be asynchronously iterated line by line::
async def read_file_lines(path: str):
async for line in open_async(path):
print(line)
:param file: the file path to open
:param args: positional arguments to :func:`open`
:param executor: the ``executor`` argument to :class:`~AsyncFileWrapper`
:param kwargs: keyword arguments to :func:`open`
:return: the wrapped file object
"""
return AsyncFileWrapper(str(file), args, kwargs, executor)
评论列表
文章目录