Display the download percentage of a file


/ Published in: Python
Save to your folder(s)

Place this snippent in your script, and call it like this:
urllib.urlretrieve(getFile, saveFile, reporthook=report)

Notice it is the 3rd argument that calls the function on each file that needs to be downloaded.


Copy this code and paste it in your HTML
  1. def report(count, blockSize, totalSize):
  2. percent = int(count*blockSize*100/totalSize)
  3. sys.stdout.write("\r%d%%" % percent + ' complete')
  4. sys.stdout.flush()
  5.  
  6. sys.stdout.write('\rFetching ' + name + '...\n')
  7. urllib.urlretrieve(getFile, saveFile, reporthook=report)
  8. sys.stdout.write("\rDownload complete, saved as %s" % (fileName) + '\n\n')
  9. sys.stdout.flush()

URL: http://stackoverflow.com/questions/51212/how-to-write-a-download-progress-indicator-in-python

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.