def download_file(url, path, overwrite=False):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
local_path = os.path.join(path, local_filename)
if os.path.isfile(local_path) and not overwrite:
return local_path
r = requests.get(url, stream=True)
with open(local_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
#f.flush() commented by recommendation from J.F.Sebastian
return local_path
评论列表
文章目录