def capacity_translate(capacity):
    """
    容量单位自动转换
    :param capacity: capacity 以B为的单位的值
    :return: 自适应单位
    """
    unit_list = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
    idx = 0
    capacity = float(capacity)
    while True:
        capacity /= 1024
        if capacity > 1024:
            idx += 1
            continue
        else:
            idx += 1
            break
    return '%0.2f' % capacity + ' ' + unit_list[idx]