utils.py 文件源码

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

项目:MMdnn 作者: Microsoft 项目源码 文件源码
def download_file(url, directory='./', local_fname=None, force_write=False):
    """Download the data from source url, unless it's already here.

    Args:
        filename: string, name of the file in the directory.
        work_directory: string, path to working directory.
        source_url: url to download from if file doesn't exist.

    Returns:
        Path to resulting file.
    """

    if not os.path.isdir(directory):
        os.mkdir(directory)

    if local_fname is None:
        local_fname = url.split('/')[-1]
    local_fname = os.path.join(directory, local_fname)

    if os.path.exists(local_fname) and not force_write:
        print ("File [{}] existed!".format(local_fname))
        return local_fname

    print ("Downloading file [{}] from [{}]".format(local_fname, url))

    try:
        import wget
        return wget.download(url, local_fname)
    except:
        return _single_thread_download(url, local_fname)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号