Skip to content

Instantly share code, notes, and snippets.

@qzcool
Last active May 3, 2018 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qzcool/d42bca05a98e8344a9d22bd30411cb4e to your computer and use it in GitHub Desktop.
Save qzcool/d42bca05a98e8344a9d22bd30411cb4e to your computer and use it in GitHub Desktop.
[Python 3.6] Download File Common Function
# Download File Common Function
def download_file(url, path):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, '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
shutil.move(local_filename,path+'/'+local_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment