Instantly share code, notes, and snippets.

What would you like to do?
Improve (using .format() instead of % string formatting)
# Improve
# (using .format() instead of % string formatting)
import sys
import urllib2
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta =
file_size = int(meta.getheaders("Content-Length")[0])
print("Downloading: {0} Bytes: {1}".format(url, file_size))
file_size_dl = 0
block_sz = 8192
while True:
buffer =
if not buffer:
file_size_dl += len(buffer)
p = float(file_size_dl) / file_size
status = r"{0} [{1:.2%}]".format(file_size_dl, p)
status = status + chr(8)*(len(status)+1)

This comment has been minimized.

bobelev commented Apr 17, 2014

What 26th line is about?


This comment has been minimized.

maddisoj commented Dec 4, 2014

@bobelev It appends a backspace character to the string for each letter in the status. Meaning the next output will be displayed over it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment