-
-
Save ktmud/72dadd142bd44b29931c1c270a11a9c8 to your computer and use it in GitHub Desktop.
Python: Human readable file size
This file contains hidden or 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 sizeof_fmt(num, suffix='o'): | |
"""Readable file size | |
:param num: Bytes value | |
:type num: int | |
:param suffix: Unit suffix (optionnal) default = o | |
:type suffix: str | |
:rtype: str | |
""" | |
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 | |
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