-
-
Save freyes/3dfa6f27ea85192e0c6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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