Skip to content

Instantly share code, notes, and snippets.

View liuzhan001st's full-sized avatar

Liu Zhan liuzhan001st

  • Beijing, China
View GitHub Profile
@liuzhan001st
liuzhan001st / human_readable_size.py
Last active January 8, 2019 03:54
Human readable size in Python
"""
source:
https://stackoverflow.com/a/1094933/8164852
"""
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)