Extracting a short using struct - won't print.
Peter Hansen
peter at engcorp.com
Thu Aug 7 14:04:52 EDT 2003
Graham Nicholls wrote:
>
> Richard Brodie wrote:
>
> >
> > "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)
>
> I told you it'd be something stupid!
> I mean
> x=data[1]
> y=data[2]
> don't I!
Yes, you do! :-) Sorry for not being more obvious about the answer,
and I thought you might figure it out yourself by using the "import pdb"
trick I showed. "Teach a man to fish" and all that. <grin>
-Peter
More information about the Python-list
mailing list