Extracting a short using struct - won't print.

Graham Nicholls graham at rockcons.co.uk
Thu Aug 7 17:44:54 CEST 2003


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]
        if debug:
                print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y))

Expecting to extract a filler byte (ignored), then a big-endian short (a
python integer) , then another of the same.  When I try to print, I get
this:

File "./pdf_merge", line 426, in getsize
    print ("DEBUG: Image [%s] is [%d] by [%d] pixels" % (self.fname,x,y))
TypeError: int argument required

What am I missing - its probably something simple - earlier I spent half an
hour wondering why I was getting a message that "img_file has no object
getsize()" from x,y=img.getsize().  It turned out to be because I had got
def getsize: indented one indent too far in the class definition.  Aaargh!

Python is 2.3b1.

Thanks
-- 
Graham Nicholls
Rock Computer Consultancy





More information about the Python-list mailing list