0

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?

abhilb
5,7572 gold badges22 silver badges26 bronze badges
asked Jan 24, 2020 at 13:15

1 Answer 1

1

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)

answered Jan 24, 2020 at 13:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.