python 文件大小显示kb、mb或gb等

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/84892999
def covertFukeSize(size):
    kb=1024;
    mb=kb*1024;
    gb=mb*1024;
    tb=gb*1024;

    if size>=tb:
        return "%.1f TB"% float(size / tb)
    if size>=gb:
        return "%.1f GB"% float(size / gb)
    if size>=mb:
        return "%.1f MB"% float(size / mb)
    if size>=kb:
        return "%.1f KB"% float(size / kb)

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/84892999