Extracting a short using struct - won't print.

Richard Brodie R.Brodie at rl.ac.uk
Thu Aug 7 18:06:22 CEST 2003


"Graham Nicholls" <graham at rockcons.co.uk> wrote in message
news:3f32779d$0$10780$afc38c87 at auth.uk.news.easynet.net...

> >>         seg_stru=">BHH"
> >>         seg_data=self.fhand.read(struct.calcsize(seg_stru))
> >>         data=struct.unpack(seg_stru,seg_data)
> >>         x=seg_data[1]
> >>         y=seg_data[2]
> >
> > Why are you unpacking the struct if you aren't going to use the
> > unpacked data?
>
> Err, I'm trying to extract two shorts - the x and y size in pixels of an
> image, which I'll use to scale it to fit another pair of parameters.  What
> makes you think I'm not using the data? Am I not - I thought I was!

You aren't using the returned value from struct.unpack() anywhere.
You need something like x, y = struct.unpack(seg_stru,seg_data)






More information about the Python-list mailing list