Re: struct is saving 4 bytes instead of 2

2007-09-13 Thread Bjoern Schliessmann
TonyB wrote: > I tried > > f.write(struct.pack('=h',thevariable)) > > and it works. Great! :) Regards, Björn -- BOFH excuse #45: virus attack, luser responsible -- http://mail.python.org/mailman/listinfo/python-list

Re: struct is saving 4 bytes instead of 2

2007-09-12 Thread TonyB
On Sep 12, 6:45 pm, Bjoern Schliessmann wrote: > TonyB wrote: > > 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? > > Use an aligment specifier in the format string (you want "standard" > alignment

Re: struct is saving 4 bytes instead of 2

2007-09-12 Thread Bjoern Schliessmann
TonyB wrote: > 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? Use an aligment specifier in the format string (you want "standard" alignment). See: http://docs.python.org/lib/module-struct.html Rega

struct is saving 4 bytes instead of 2

2007-09-12 Thread 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