Skip to content

Instantly share code, notes, and snippets.

@abbotto
Created August 16, 2013 12:55
Show Gist options
  • Save abbotto/6249651 to your computer and use it in GitHub Desktop.
Save abbotto/6249651 to your computer and use it in GitHub Desktop.
Python: Display the download percentage of a file
def report(count, blockSize, totalSize):
percent = int(count*blockSize*100/totalSize)
sys.stdout.write("\r%d%%" % percent + ' complete')
sys.stdout.flush()
sys.stdout.write('\rFetching ' + name + '...\n')
urllib.urlretrieve(getFile, saveFile, reporthook=report)
sys.stdout.write("\rDownload complete, saved as %s" % (fileName) + '\n\n')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment