Last active
January 16, 2017 00:18
-
-
Save joshland/87b07ea63a250491561dde5b887a516d 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
import collections | |
def humanize_bibytes(n, prefixes=collections.OrderedDict(( | |
(0, 'B'), | |
(1024, 'KiB'), | |
(1048576, 'MiB'), | |
(1073741824, 'GiB'), | |
(1099511627776, 'TiB'), | |
(1125899906842624, 'PiB'), | |
(1152921504606846976, 'EiB'), | |
(1180591620717411303424, 'ZiB'), | |
(1208925819614629174706176, 'YiB')))): | |
''' Convert big numbers into easily-human-readable ones. | |
''' | |
for value, prefix in reversed(prefixes.items()): | |
if n >= value: | |
return '{:.2f} {}'.format(float(n) / value, prefix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment