hi, im trying to read a 4 byte integer from a binary file, only trouble is, the file is in bigendian format and no matter what i try i cant seem to make python read it big endian,
does anyone know how to read big endian files in python
hi, im trying to read a 4 byte integer from a binary file, only trouble is, the file is in bigendian format and no matter what i try i cant seem to make python read it big endian,
does anyone know how to read big endian files in python
Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
My LastFM profile
want to Give each GTK program its own theme? well look Here
is there any chance you can send me this big-endian file ? or a sample big-endian file ?
well, if it is just an 4 bytes integer you could do this:
from struct import unpack
file = open('file', 'rb')
be_int = file.read(4)
le_int = unpack('>L', be_int) # > for big endian, < for little endian
im willing to bet you have a bigendian file on your computer any mp3 is big endian, (or at least the metadata is)
Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
My LastFM profile
want to Give each GTK program its own theme? well look Here
it gets complicated to read variable lenght data in big endian format while im using a little endian machine, but if you know the lenght of data, like int 4 bytes it is a lot easier. Did you try the solution I told you ?
i get aerror is there something i need to import?global name 'unpack' is not defined
Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
My LastFM profile
want to Give each GTK program its own theme? well look Here
first line: from struct import unpack
ah yeah sorry, my bad missed it
still get an erro though,
thx 4 ur help btwFile "basictreeview (copy).py", line 312, in add_event
self.import_meta_info(lotsafiles.pop())
File "basictreeview (copy).py", line 268, in import_meta_info
title = self.import_id3v2_title(data)
File "basictreeview (copy).py", line 216, in import_id3v2_title
le_int = unpack('>',last)
struct.error: unpack str size does not match format
the code is this
f = open(data, "rb")
from struct import unpack
f.seek(6)
x = 0
last = f.read(4)
le_int = unpack('>',last)
print last
Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
My LastFM profile
want to Give each GTK program its own theme? well look Here
that is why I asked you to send me the file, I just can't guess at what position your integer would be.
it is an mp3 file, its always at the same place because of the specification, cant really send an mp3 file
read from the ver start of the file
first 3 bytes always = "ID3"
next 2 bytes will be "0n 00" where n is a number from 1 to 4
next byte needs to be read as binary for flags
next 4 bytes are the size of the metadata, in this case its "00 00 08 67" which when read big endian is 2151 (right) in little endian is 1728577536 (not right)
ive verified in a hex editor too
Jeremy Clarkson - "A Dazzling Hero of Political Incorrectness"
My LastFM profile
want to Give each GTK program its own theme? well look Here
Bookmarks