Skip to content

Instantly share code, notes, and snippets.

@mikemadisonweb
Created March 20, 2017 06:35
Show Gist options
  • Save mikemadisonweb/f121c7cc83504519eb8e00a9247512c6 to your computer and use it in GitHub Desktop.
Save mikemadisonweb/f121c7cc83504519eb8e00a9247512c6 to your computer and use it in GitHub Desktop.
Function for human readable file size formatting
def sizeof_fmt(num, suffix='B'):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment