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

 

posted @ 2018-02-02 15:54  lichenxi  阅读(1788)  评论(0编辑  收藏  举报