struct is saving 4 bytes instead of 2

T

TonyB

Using UBUNTU python 2.4.3 I'm using struct to save a variable to a
file. My goal is to save it as a 2 byte signed integer. Its being
saved using:

f.write(struct.pack('h',thevariable))

When I inspect the file with a hex editor it show that the variable is
being saved as 4 bytes. How can I make it save the value as 2 bytes?

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top