/ Published in: Python

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.
urllib.urlretrieve(getFile, saveFile, reporthook=report)
Notice it is the 3rd argument that calls the function on each file that needs to be downloaded.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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()
URL: http://stackoverflow.com/questions/51212/how-to-write-a-download-progress-indicator-in-python
Comments
