table_remote.py 文件源码

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

项目:agate-remote 作者: wireservice 项目源码 文件源码
def from_url(cls, url, callback=agate.Table.from_csv, binary=False, **kwargs):
    """
    Download a remote file and pass it to a :class:`.Table` parser.

    :param url:
        URL to a file to load.
    :param callback:
        The method to invoke to create the table. Typically either
        :meth:`agate.Table.from_csv` or :meth:`agate.Table.from_json`, but
        it could also be a method provided by an extension.
    :param binary:
        If :code:`False` the downloaded data will be processed as a string,
        otherwise it will be treated as binary data. (e.g. for Excel files)
    """
    r = requests.get(url)

    if binary:
        content = six.BytesIO(r.content)
    else:
        if six.PY2:
            content = six.StringIO(r.content.decode('utf-8'))
        else:
            content = six.StringIO(r.text)

    return callback(content, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号