python bytes字节换算
python bytes字节换算 |
#!/usr/bin/env python
# -*- coidng:utf-8 -*-
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