Skip to content

Instantly share code, notes, and snippets.

@deleted
Created April 15, 2010 22:44
Show Gist options
  • Save deleted/367764 to your computer and use it in GitHub Desktop.
Save deleted/367764 to your computer and use it in GitHub Desktop.
def sizeof_human(numbytes):
''' Human-readable size strings '''
if numbytes < 0: # urlretrieve passes -1 for totalsize if it can't get the filesize from the server
return '???'
for x in ['bytes','KB','MB','GB','TB','PB']:
if numbytes < 1024.0:
return "%3.2f%s" % (numbytes, x)
numbytes /= 1024.0
else:
return "Exabytes!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment