def format_memory(val):
    val = float(val)
    if val < KB:
        label = "B"
    elif KB < val < KB ** 2:
        label = "KB"
        val /= KB
    elif KB ** 2 < val < KB ** 3:
        label = "MB"
        val /= KB ** 2
    # elif val > KB**3:
    else:
        label = "GB"
        val /= KB ** 3
    return str(round(val, 2)) + label
Pretty formatting of memory.
dataset/ETHPy150Open ccpgames/rescache/format_memory.py/format_memory