Skip to content

Instantly share code, notes, and snippets.

@sloat
Last active January 6, 2016 22:10
Show Gist options
  • Save sloat/b99d1df57189598d98d3 to your computer and use it in GitHub Desktop.
Save sloat/b99d1df57189598d98d3 to your computer and use it in GitHub Desktop.
filesize shortened with labels
import math
def short_filesize(size):
labels = ['B', 'KB', 'MB', 'GB', 'TB']
index = min(int(math.floor(math.log(size, 1024))), len(labels))
short = size / 1024**index
return '%.2f%s' % (short, labels[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment