Can somebody please tell me how do I read the result b'\\x9a\\x99\\x99?' of
import struct
data = struct.pack("@f", 1.2)
print(data)
What does \\x9a
represent? Or \\x99
? How do I translate this back to 1.2
?
The data is stored in a binary format. To get the value back, use struct.unpack
:
import struct
data = struct.pack("@f",1.2)
print(struct.unpack("@f",data))
Related: Why won't Python display this text correctly? (UTF-8 Decoding Issue)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.