比较简单,直接干货,说明写在工具方法的注释里了: # bytes 文件大小,单位:字节数bytes # precision 小数点后位数,可以是0 def readable_file_size(bytes, precision): for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']: if abs(bytes) < 1024.0: return '%s %s' % (format(bytes, '.%df' % precision), uni…