Skip to content

Instantly share code, notes, and snippets.

@kamyar1979
Created October 5, 2012 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamyar1979/3837527 to your computer and use it in GitHub Desktop.
Save kamyar1979/3837527 to your computer and use it in GitHub Desktop.
Python file size formatter
def __repr__(self):
suf = 'BKMGTPEZY'
temp = self.size >> 10
index = 0
while temp:
temp >>= 10
index += 1
return '%g%s' % (round(float(self.size) / (1 << (10 * index)), 1), suf[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment