Last active
March 20, 2018 03:28
-
-
Save tamsanh/67be70ac13726deaa1c0995c5da0660e to your computer and use it in GitHub Desktop.
Get a human readable filesize of the output
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
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