如何在Python中将十六进制字符串转换为文本?
我有一个十六进制字符串
0x3C503E3235206D4C206F662033204D2048436C207765726520616464656420746F203735206D4C206F6620302E3035204D2048436C2E20546865206D6F6C6172697479206F662048436C20696E2074686520726573756C74696E6720736F6C7574696F6E20202026656D73703B26656D73703B26656D73703B26656D73703B2020200D0A20202026656D73703B26656D73703B26656D73703B26656D73703B2020697320617070726F78696D6174656C792D
,我想借助Python将其转换为文本。我该怎么办?
我已经尝试过了
print(bytes.fromhex(xyz))
其中xyz
是存储此字符串的我的变量,但出现此错误
在位置1的fromhex()arg中发现非十六进制数
答案 0 :(得分:4)
只需从字符串开头将'0x'斩掉即可。所以
print(bytes.fromhex(var[2:]))
会给予
b'<P>25 mL of 3 M HCl were added to 75 mL of 0.05 M HCl. The molarity of HCl in the resulting solution      \r\n      is approximately-'