Skip to content

Instantly share code, notes, and snippets.

@tamsanh
Last active March 20, 2018 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsanh/67be70ac13726deaa1c0995c5da0660e to your computer and use it in GitHub Desktop.
Save tamsanh/67be70ac13726deaa1c0995c5da0660e to your computer and use it in GitHub Desktop.
Get a human readable filesize of the output
from __future__ import print
# Adopted from
# https://web.archive.org/web/20111010015624/http://blogmag.net/blog/read/38/Print_human_readable_file_size
# https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
def sizeof_fmt(num, suffix='B'):
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
else:
return "%.1f%s%s" % (num, 'Y', suffix)
if __name__ == "__main__":
import sys
print(sizeof_fmt(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment