file.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:asyncio_extras 作者: agronholm 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号