📌  相关文章
📜  python 以 mb 为单位获取文件大小 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:05.851000             🧑  作者: Mango

代码示例2
import math

def convert_size(size_bytes):
   if size_bytes == 0:
       return "0B"
   size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
   i = int(math.floor(math.log(size_bytes, 1024)))
   p = math.pow(1024, i)
   s = round(size_bytes / p, 2)
   return "%s %s" % (s, size_name[i])