Created
February 26, 2021 05:57
-
-
Save kebyn/087dc4dbddddce5094ae52b98fc13a75 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
def bytes2human(in_bytes: int) -> str: | |
''' | |
''' | |
suffixes = ('B', 'KB', 'MB', 'GB', 'TB', 'PB') | |
suffix = 0 | |
while in_bytes > 9999 and suffix < len(suffixes): | |
in_bytes = in_bytes >> 10 | |
suffix += 1 | |
if suffix >= len(suffixes): | |
suffix -= 1 | |
return "{}{}".format(in_bytes, suffixes[suffix]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment