Created
January 26, 2023 13:13
-
-
Save Erica-Iris/b7106d829e318d145f6260237bc1042e to your computer and use it in GitHub Desktop.
sizeof_fmt
This file contains hidden or 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
def sizeof_fmt(num, suffix="iB"): | |
for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: | |
if abs(num) < 1024.0: | |
return "%3.2f%s%s" % (num, unit, suffix) | |
num /= 1024.0 | |
return "%.2f%s%s" % (num, "Y", suffix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment