integer woes...

Dave Cole djc at object-craft.com.au
Wed Feb 19 05:49:51 CET 2003


> On Wed, 19 Feb 2003 1:50 pm, Luke McCarthy wrote:
> > I have written an ID3v1 MP3 tag reader, but I have one slight problem. The
> >
> > track number is a two-byte integer and reads into Python like so:
> > >>> tag.track
> >
> > '\x00\x17'
> >
> > (in this example, the track number is 23, which is hex 17)
> 
> >>> s='\x00\x17'
> >>> ord(s[0])
> 0
> >>> ord(s[1])
> 23
> >>> map(ord, s)
> [0, 23]

Or...

>>> import struct
>>> struct.unpack('>h', '\x00\x17')
(23,)

- Dave

-- 
http://www.object-craft.com.au




More information about the Python-list mailing list