integer woes...

Luke McCarthy luke at ukonline.co.uk
Tue Feb 18 22:30:03 EST 2003


Thanks, sometimes you just need pointing in the right direction :)

For anyone who's interested, here's the code I used:

import struct
tag.track = struct.unpack('>h', tag.track)[0]

The index is needed because the unpack function returns a tuple. The track
number is stored in big-endian order so you also need the '>'.

Luke McCarthy

"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message
news:7xd6lpf02l.fsf at ruckus.brouhaha.com...
> "Luke McCarthy" <luke at ukonline.co.uk> writes:
> > >>> tag.track
> > '\x00\x17'
> >
> > (in this example, the track number is 23, which is hex 17)
> >
> > My dilemma: how can I convert this into an integer?
>
> See the struct module.
>
> > Whoever designed these tags must be weird. Why was the track number a
short
> > int yet the year a string??? Why make artist, title and album 30 chars
long
> > yet make the comment 28 chars long???
>
> It's really pretty silly, trying to save a few bytes in a file that is
> typicall megabytes.






More information about the Python-list mailing list