Skip to content

Instantly share code, notes, and snippets.

@jdelafon
Created April 5, 2016 07:49
Show Gist options
  • Save jdelafon/3181b4233329fd76bfcc7a99ec43ee86 to your computer and use it in GitHub Desktop.
Save jdelafon/3181b4233329fd76bfcc7a99ec43ee86 to your computer and use it in GitHub Desktop.
Change number of bytes to human-readable file size
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