我有一个十六进制字符串:
Hex = 'E388854083969497A4A38599408881A2409985829696A38584408699969440814082A48783888583924B'
作为字节对象,它看起来像这样:
b'\xe3\x88\x85@'b'\xe3\x88\x85@\x83\x96\x94\x97\xa4'b'\xe3\x88\x85@'b'\xe3\x88\x85@\x83\x96\x94\x97\xa4'b'\xe3\x88\x85@\x83'b'\xe3\x88'b'\xe3\x88\x85@\x83\x96\x94\x97\xa4'
在 EBCDIC 中是这样的:
The computer has rebooted from a bugcheck.
所以我知道十六进制 40 (x40) 在 EBCDIC 中是一个“空格”,在 ASCII 中是一个“@”
我不明白为什么 python 在打印字节对象时打印“@”而不是“\x40”
我的测试代码示例是:
import codecs
Hex = 'E388854083969497A4A38599408881A2409985829696A38584408699969440814082A48783888583924B'
output = []
DDF = [4,9,4,9,5,2,9]
distance = 0
# This breaks my hex string into chunks based off the list 'DDF'
for x in DDF:
output.append(Hex[distance:x*2+distance])
distance += x*2
#This prints out the list of hex strings
for x in output:
print(x)
#This prints out they byte objects in the list
for x in output:
x = codecs.decode(x, "hex")
print(x)
#The next line print the correct text
Hex = codecs.decode(Hex, "hex")
print(codecs.decode(Hex, 'cp1140'))
上面的输出是:
E3888540
83969497A4A3859940
8881A240
9985829696A3858440
8699969440
8140
82A48783888583924B
b'\xe3\x88\x85@'
b'\x83\x96\x94\x97\xa4\xa3\x85\x99@'
b'\x88\x81\xa2@'
b'\x99\x85\x82\x96\x96\xa3\x85\x84@'
b'\x86\x99\x96\x94@'
b'\x81@'
b'\x82\xa4\x87\x83\x88\x85\x83\x92K'
The computer has rebooted from a bugcheck.
所以我想我的问题是如何让 python 将字节对象打印为“x40”而不是“@”
非常感谢你的帮助 :)