import io
import os, gzip, re
def byte_1gram(byte_code):
OneByte = [0]*16**2
for row in byte_code:
codes = row[:-2].split()[1:]
# Convert code to 1byte
OneByteCode = []
for i in codes:
if i != '??':
OneByteCode += [int(i,16)]
# Calculate the frequency of 1byte
for i in OneByteCode:
OneByte[i] += 1
return OneByte
with open('0ACDbR5M3ZhBJajygTuf.bytes', 'rb') as f:
print(byte_1gram(f))
13 for i in codes:
14 if i != '??':
---> 15 OneByteCode += [int(i,16)]
16
17 #Calculate the frequency of 1byte
Value Error: invalid literal for int() with base 16: b'??'
我想读取字节并提取1克特征,但是在第15行,它给出了像int()
这样的无效文字的错误答案 0 :(得分:0)
您的问题是您按'??'
过滤 - 这是一个常规字符串,但您遇到的字符串是b'??'
- 字节类型(仅在Python3中)。它们不相等,因此过滤器不起作用。
将'??'
更改为b'??'
。