Skip to content

Instantly share code, notes, and snippets.

@sxd
Created December 18, 2014 15:55
Show Gist options
  • Save sxd/cea9b07e3514e9f5feb9 to your computer and use it in GitHub Desktop.
Save sxd/cea9b07e3514e9f5feb9 to your computer and use it in GitHub Desktop.
python convert
def size_suffix(bytes):
convertion = [
(1024 ** 5, 'P'),
(1024 ** 4, 'T'),
(1024 ** 3, 'G'),
(1024 ** 2, 'M'),
(1024 ** 1, 'K'),
(1024 ** 0, 'B'),
]
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