如何在python中将十六进制字符串转换为文本

2024-04-25 22:12:27 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Python中将十六进制字符串转换为文本?你知道吗

我有一个十六进制字符串

0x3C503E3235206D4C206F662033204D2048436C207765726520616464656420746F203735206D4C206F6620302E3035204D2048436C2E20546865206D6F6C6172697479206F662048436C20696E2074686520726573756C74696E6720736F6C7574696F6E20202026656D73703B26656D73703B26656D73703B26656D73703B2020200D0A20202026656D73703B26656D73703B26656D73703B26656D73703B2020697320617070726F78696D6174656C792D

我想用Python把它转换成文本。我该怎么做?你知道吗

我试过这个

print(bytes.fromhex(xyz))

其中xyz是存储该字符串的变量,但我得到了这个错误

non-hexadecimal number found in fromhex() arg at position 1


Tags: 字符串in文本numberbytes错误arg中将
1条回答
网友
1楼 · 发布于 2024-04-25 22:12:27

只需从字符串的开头切掉“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   &emsp;&emsp;&emsp;&emsp;   \r\n   &emsp;&emsp;&emsp;&emsp;  is approximately-'

相关问题 更多 >