def filesize(size):
    size_name = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
    if int(size) > 0:
        i = int(math.floor(math.log(size, 1024)))
        p = math.pow(1024, i)
        s = round(size / p, 3)
        if s > 0:
            return '%s %s' % (s, size_name[i])
    return '0 B'
Pretty-print file size from bytes.
dataset/ETHPy150Open j-bennet/wharfee/wharfee/helpers.py/filesize