我正在写一个python脚本,它查看常见的计算机文件,并检查它们是否有相似的字节、单词、双字。虽然我需要/想要查看十六进制的文件,但ande似乎无法真正让python用python打开一个简单的文件。我试过了编解码器.打开使用hex作为编码,但是当我操作文件描述符时,它总是会吐出来File "main.py", line 41, in
main()
File "main.py", line 38, in main
process_file(sys.argv[1])
File "main.py", line 27, in process_file
seeker(line.rstrip("\n"))
File "main.py", line 15, in seeker
for unit in f.read(2):
File "/usr/lib/python2.6/codecs.py", line 666, in read
return self.reader.read(size)
File "/usr/lib/python2.6/codecs.py", line 472, in read
newchars, decodedbytes = self.decode(data, self.errors)
File "/usr/lib/python2.6/encodings/hex_codec.py", line 50, in decode
return hex_decode(input,errors)
File "/usr/lib/python2.6/encodings/hex_codec.py", line 42, in hex_decode
output = binascii.a2b_hex(input)
TypeError: Non-hexadecimal digit found
def seeker(_file):
f = codecs.open(_file, "rb", "hex")
for LINE in f.read():
print LINE
f.close()
我真的只想看到文件,并对它们进行操作,就像在xxd这样的十六进制编辑器中一样。也有可能一次以一个字的增量读取一个文件。在
不,这不是家庭作业。在