[英]How do I read the result of a python struct?
Can somebody please tell me how do I read the result b'\\x9a\\x99\\x99?'有人可以告诉我如何读取结果 b'\\x9a\\x99\\x99 吗? of
的
import struct
data = struct.pack("@f", 1.2)
print(data)
What does \\x9a
represent? \\x9a
代表什么? Or \\x99
?还是
\\x99
? How do I translate this back to 1.2
?我如何将其翻译回
1.2
?
The data is stored in a binary format.数据以二进制格式存储。 To get the value back, use
struct.unpack
:要取回值,请使用
struct.unpack
:
import struct
data = struct.pack("@f",1.2)
print(struct.unpack("@f",data))
Related: Why won't Python display this text correctly?相关:为什么 Python 不能正确显示此文本? (UTF-8 Decoding Issue)
(UTF-8 解码问题)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.