def download_file(url, local_filename):
"""
Downloads a file from an url to a local file.
Args:
url (str): url to download from.
local_filename (str): local file to download to.
Returns:
str: file name of the downloaded file.
"""
r = requests.get(url, stream=True)
if path.dirname(local_filename) and not path.isdir(path.dirname(local_filename)):
raise Exception(local_filename)
makedirs(path.dirname(local_filename))
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
return local_filename
评论列表
文章目录