python get human readable file size

Solutions on MaxInterview for python get human readable file size by the best coders in the world

showing results for - "python get human readable file size"
Giulio
24 Feb 2017
1def human_readable_size(size, decimal_places=3):
2    for unit in ['B','KiB','MiB','GiB','TiB']:
3        if size < 1024.0:
4            break
5        size /= 1024.0
6    return f"{size:.{decimal_places}f}{unit}"