-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrans_bytes_human.py
More file actions
28 lines (26 loc) · 855 Bytes
/
trans_bytes_human.py
File metadata and controls
28 lines (26 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# encoding=utf8
"""
转换字节数为友好单位
"""
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import time
import threading
import os
def get_bytes(size):
"""
字节转换
:param size:
:return:
"""
if abs(size) < 1024:
return str(size) + ' byte'
elif abs(size) >= 1024 and abs(size) < 1024 * 1024:
return str(round(size / 1024.0)) + ' KB'
elif abs(size) >= 1024 * 1024 and abs(size) < 1024 * 1024 * 1024:
return str(round(size / 1024.0 / 1024.0)) + ' MB'
elif abs(size) >= 1024 * 1024 * 1024 and abs(size) < 1024 * 1024 * 1024 * 1024:
return str(round(size / 1024.0 / 1024.0 / 1024.0)) + ' GB'
elif abs(size) >= 1024 * 1024 * 1024 * 1024 and abs(size) < 1024 * 1024 * 1024 * 1024 * 1024:
return str(round(size / 1024.0 / 1024.0 / 1024.0 / 1024.0, 2)) + ' TB'