python bytes字节换算 |
def bytes_conversion(number): symbols = (‘K‘,‘M‘,‘G‘,‘T‘,‘P‘,‘E‘,‘Z‘,‘Y‘) prefix = dict() for i,s in enumerate(symbols): prefix[s] = 1<<(i+1) *10 for s in reversed(symbols): if int(number) >= prefix[s]: value = float(number) / prefix[s] return ‘%.2f%s‘ %(value,s) return "%sB" %number
原文地址:https://www.cnblogs.com/simple001/p/8405582.html
时间: 2024-11-10 16:20:43