def byte_convert(bytes: int): # 定义单位 units = ["Bytes", "KB", "MB", "GB", "TB"] unit_index = 0 # 迭代转换单位,直到值小于1024 while bytes >= 1024 and unit_index < len(units) - 1: bytes /= 1024.0 unit_index += 1 # 返回结果 return f"{bytes:.2f}{units[unit_index]}"