Created
April 5, 2016 07:49
-
-
Save jdelafon/3181b4233329fd76bfcc7a99ec43ee86 to your computer and use it in GitHub Desktop.
Change number of bytes to human-readable file size
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 readable_size(num): | |
"""Change number of bytes to human-readable file size""" | |
for unit in ['','K','M','G','T','P','E','Z']: | |
if abs(num) < 1024.0: | |
return "%3.1f%sB" % (num, unit) | |
num /= 1024.0 | |
return "%.1f%s%s" % (num, 'Yi', 'B') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment