Skip to content

Instantly share code, notes, and snippets.

@ngaloppo
Created November 23, 2015 19:23
Show Gist options
  • Save ngaloppo/0cc19af946296c7478fa to your computer and use it in GitHub Desktop.
Save ngaloppo/0cc19af946296c7478fa to your computer and use it in GitHub Desktop.
def format_bytes(n):
order = 0
while n > 1024:
order += 1
n //= 1024
return '%d%sB' % (n, ('', 'k', 'M', 'G', 'T', 'P')[order])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment