这篇文章主要介绍了Python字节单位转换(将字节转换为K M G T),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
def bytes_to_human(n): symbols = ('K','M','G','T','P','E','Z','Y') prefix = {} for i,s in enumerate(symbols): prefix[s] = 1 = prefix[s]: value = float(n) / prefix[s] return '%.1f%s' % (value,s) return '%sB' % n
python编写的储存单位转换代码(以字节(B)为单位)
def bytes(bytes): if bytes = 1024 and bytes = 1024 * 1024 and bytes = 1024 * 1024 * 1024 and bytes = 1024 * 1024 * 1024 * 1024 and bytes = 1024 * 1024 * 1024 * 1024 * 1024 and bytes = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 and bytes
测试:
"D:Program FilesPythonpython36python.exe" C:/Users/Jochen/PycharmProjects/mysite/bytes.py
0:0 B
1:1 B
2:10 B
3:100 B
4:1000 B
5:9.77 KB
6:97.66 KB
7:976.56 KB
8:9.54 MB
9:95.37 MB
10:953.67 MB
11:9.31 GB
12:93.13 GB
13:931.32 GB
14:9.09 TB
15:90.95 TB
16:909.49 TB
17:8.88 PB
18:88.82 PB
19:888.18 PB
20:8.67 EB
20:86.74 EB
20:867.36 EB
Process finished with exit code 0
到此这篇关于Python字节单位转换(将字节转换为K M G T)的文章就介绍到这了,更多相关Python字节单位转换内容请搜索编程之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程之家!