python 将文件大小转换为human readable 的大小表示

定义了一个函数,

def HRS(size):
    units=('B','KB','MB','GB','TB','PB')
    for i in range(len(units)-1,-1,-1):
        if size>=2*(1024**i):
            return str(size/(1024**i))+' '+units[i]

HRS表示 human readable size。

原文地址:https://www.cnblogs.com/vanwoos/p/8482983.html