How to write a download progress indicator in Python?

10:26
import urllib, sys
import tarfile
 
rem_file = 'http://blah.blah.com/dir/filename.tar.gz'
loc_file = 'filename.tar.gz'
 
def dlProgress(count, blockSize, totalSize):
percent = int(count*blockSize*100/totalSize)
sys.stdout.write("\r" + rem_file + "...%d%%" % percent)
sys.stdout.flush()
 
tpl = urllib.urlretrieve(rem_file, loc_file, reporthook=dlProgress)
tar = tarfile.open(loc_file)
tar.extractall()
tar.close()