Skip to content

Instantly share code, notes, and snippets.

@freyes
Forked from sxd/gist:cea9b07e3514e9f5feb9
Last active August 29, 2015 14:11
Show Gist options
  • Save freyes/3dfa6f27ea85192e0c6e to your computer and use it in GitHub Desktop.
Save freyes/3dfa6f27ea85192e0c6e to your computer and use it in GitHub Desktop.
convertion = [
(1024 ** 5, 'P'),
(1024 ** 4, 'T'),
(1024 ** 3, 'G'),
(1024 ** 2, 'M'),
(1024 ** 1, 'K'),
(1024 ** 0, 'B'),
]
def size_suffix(bytes):
bytes = int(bytes)
for factor, suffix in convertion:
if bytes >= factor:
break
total = bytes / factor
return str(total) + suffix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment