色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Python字節(jié)單位轉(zhuǎn)換(將字節(jié)轉(zhuǎn)換為K M G T)

瀏覽:18日期:2022-06-26 16:03:13

def bytes_to_human(n): symbols = (’K’,’M’,’G’,’T’,’P’,’E’,’Z’,’Y’) prefix = {} for i,s in enumerate(symbols): prefix[s] = 1 << (i + 1) * 10 for s in reversed(symbols): if n >= prefix[s]: value = float(n) / prefix[s] return ’%.1f%s’ % (value,s) return ’%sB’ % npython編寫的儲存單位轉(zhuǎn)換代碼(以字節(jié)(B)為單位)

def bytes(bytes): if bytes < 1024: #比特 bytes = str(round(bytes, 2)) + ’ B’ #字節(jié) elif bytes >= 1024 and bytes < 1024 * 1024: bytes = str(round(bytes / 1024, 2)) + ’ KB’ #千字節(jié) elif bytes >= 1024 * 1024 and bytes < 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024, 2)) + ’ MB’ #兆字節(jié) elif bytes >= 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024, 2)) + ’ GB’ #千兆字節(jié) elif bytes >= 1024 * 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024 / 1024, 2)) + ’ TB’ #太字節(jié) elif bytes >= 1024 * 1024 * 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024 / 1024 / 1024, 2)) + ’ PB’ #拍字節(jié) elif bytes >= 1024 * 1024 * 1024 * 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024 / 1024 / 1024 /1024, 2)) + ’ EB’ #艾字節(jié) return bytes if __name__ == ’__main__’: print(’0:’ + bytes(0)) print(’1:’ + bytes(1)) print(’2:’ + bytes(10)) print(’3:’ + bytes(100)) print(’4:’ + bytes(1000)) print(’5:’ + bytes(10000)) print(’6:’ + bytes(100000)) print(’7:’ + bytes(1000000)) print(’8:’ + bytes(10000000)) print(’9:’ + bytes(100000000)) print(’10:’ + bytes(1000000000)) print(’11:’ + bytes(10000000000)) print(’12:’ + bytes(100000000000)) print(’13:’ + bytes(1000000000000)) print(’14:’ + bytes(10000000000000)) print(’15:’ + bytes(100000000000000)) print(’16:’ + bytes(1000000000000000)) print(’17:’ + bytes(10000000000000000)) print(’18:’ + bytes(100000000000000000)) print(’19:’ + bytes(1000000000000000000)) print(’20:’ + bytes(10000000000000000000)) print(’20:’ + bytes(100000000000000000000)) print(’20:’ + bytes(1000000000000000000000))

測試:

'D:Program FilesPythonPython36python.exe' C:/Users/Jochen/PycharmProjects/mysite/bytes.py0:0 B1:1 B2:10 B3:100 B4:1000 B5:9.77 KB6:97.66 KB7:976.56 KB8:9.54 MB9:95.37 MB10:953.67 MB11:9.31 GB12:93.13 GB13:931.32 GB14:9.09 TB15:90.95 TB16:909.49 TB17:8.88 PB18:88.82 PB19:888.18 PB20:8.67 EB20:86.74 EB20:867.36 EB

Process finished with exit code 0

到此這篇關(guān)于Python字節(jié)單位轉(zhuǎn)換(將字節(jié)轉(zhuǎn)換為K M G T)的文章就介紹到這了,更多相關(guān)Python字節(jié)單位轉(zhuǎn)換內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 97影院在线午夜 | 久久怡红院国产精品 | 国产一级a毛片高清 | 久久久综合网 | 国产成人永久免费视频 | 亚洲精品一区二区中文 | 久久香蕉精品视频 | 久久久久在线 | 日本aaaa片毛片免费 | 视频一区在线播放 | 999久久久精品视频在线观看 | 亚洲国产精品久久久久 | 久草最新视频 | 中文字幕一区在线播放 | 精品一区二区三区波多野结衣 | 亚洲综合色吧 | 欧美成人免费高清二区三区 | 成人伊人青草久久综合网 | 91原创在线 | 国产精品久久久久久影视 | 精品国产高清不卡毛片 | 欧美日本视频一区 | 欧美日韩亚洲国产精品 | 国外精品视频在线观看免费 | 国产一久久香蕉国产线看观看 | 成a人v | 久久久久欧美精品网站 | 国产八区| 国产亚洲精品一区二区三区 | 久视频在线观看 | 日韩欧美视频一区 | 免费一级夫妻a | 成人国产精品久久久免费 | 美女张开腿让男人桶爽动漫视频 | 免费黄网大全 | 亚洲最大免费视频网 | re久久| 日本国产一区二区三区 | 成人在线免费 | 欧美a在线看 | 午夜视频久久 |