I was searching for python script to download files and I found 2 ways of downloading with urllib.request.urlopen
. One of them use shutil
module and the other one not.
Now I want to know what is the difference between these 2 script?
# 1:
import urllib
filedata = urllib.request.urlopen('http://download.thinkbroadband.com/10MB.zip')
datatowrite = filedata.read()
with open('10MB.zip', 'wb') as f:
f.write(datatowrite)
# 2:
import urllib,shutil
with urllib.request.urlopen('http://download.thinkbroadband.com/10MB.zip') as response, open("10MB.zip", 'wb') as f:
shutil.copyfileobj(response, f)