Extracting a short using struct - won't print.

Peter Hansen peter at engcorp.com
Thu Aug 7 11:51:42 EDT 2003


Graham Nicholls wrote:
> 
> Thanks to Richard and Alex, I'm doing this:
> 
>         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?

>         if debug:
>                 print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y))

Best way to troubleshoot this kind of thing, in my experience,
is to insert "import pdb; pdb.set_trace()" into the code just
above the failing line, then use the debugger to inspect the
values directly just before they are used.  (You need to execute
the "r" or "return" command immediately after the debugger is
entered... the rest is pretty straightforward to learn.)

-Peter




More information about the Python-list mailing list