def size(bytes, system=byte):
    for factor, suffix in system:
        if bytes >= factor:
            break
    amount = bytes/factor
    if isinstance(suffix, tuple):
        singular, multiple = suffix
        if amount == 1:
            suffix = singular
        else:
            suffix = multiple
    if type(amount) == float:
        return "%0.3f%s" % (amount,suffix)
    else:
        return str(amount) + suffix
Human-readable file size.
dataset/ETHPy150Open aerospike/aerospike-admin/lib/filesize.py/size