![](/img/trans.png)
[英]I don't know why I get the multiple graphs of W versus PT using the attached python code
[英]I don't know why I get two backslashes (python)
t = '.EA.B2.80.EB.A7.88'
t = t.replace('.','\\x').lower()
string1 = b"\xea\xb2\x80\xeb\xa7\x88"
print(string1.decode("utf-8"))
string2 = bytes(t, "utf-8")
print(string2)
print(string2.decode("utf-8"))
String1 返回了我想要的解码值,但 string2 返回了两个反斜杠。 我认为 string1 和 string2 没有什么不同,但想知道为什么 string2 返回两个反斜杠。 有人可以回答这个吗? 感谢您的阅读!
在string1
中,反斜杠是bytes
文字语法的一部分,用于在结果值中生成正确的字节。
您正在向字符串t
的值添加文字反斜杠。
我不确定这是最好的解决方案,但是您可以将t
转换为可以传递给bytes
的int
值序列。
string2 = bytes(int(x, 16) for x in t.strip(".").split("."))
更新:有一些更简单的东西:
string2 = bytes.fromhex(t.replace(".", ""))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.