发布时间:2019-09-21 11:00:14编辑:auto阅读(1894)
from functools import partial
i = 0
f = open('lgtm-monitor.dat', 'rb')
f2 = open('f.txt', 'w')
records = iter(partial(f.read, 2), b'') # 每次2字节
for r in records:
j = 0
r_int = int.from_bytes(r, byteorder='big') #将 byte转化为 int
i += 1
print('i={0}:{1}'.format(i, r_int))
f2.write(str(r_int)+' ')
if 8==i:
f2.write('\n')
i = 0
break
f.close()
f2.close()
二进制文件使用 read( size)
with open('lgtm-monitor.dat', 'rb') as fp:
data = fp.read(2) #type(data) === bytes
text = int.from_bytes(data, byteorder='big')
fp.close()
上一篇: 用Python将一个列表分割成小列表
下一篇: MAC上打包python
47838
46382
37269
34724
29310
25967
24898
19945
19536
18017
5787°
6407°
5922°
5958°
7061°
5906°
5938°
6434°
6401°
7772°