We had DataInputStream for processing binary files in Java; what can we use for these files in Python?
-
2read this post: stackoverflow.com/questions/1035340/… and this one too: stackoverflow.com/questions/8710456/…theAlse– theAlse2013-03-15 09:05:05 +00:00Commented Mar 15, 2013 at 9:05
-
Does you code need to be compatible with DataInputStream's file format?Ber– Ber2013-03-15 09:24:29 +00:00Commented Mar 15, 2013 at 9:24
3 Answers
I have used the Construct package a lot to read and parse structures data in Python.
Basically it lets you declare the file's structure in a very idiomatic and pythonic way and than parses or encode it for you.
After parsing you have an object that allows access to all the file's information via attributes.
Comments
Few years ago I used struct module to parse binary responses from several game servers http://docs.python.org/2/library/struct.html#struct.unpack
Sometimes it's usefull just to .find() some bytes in data, like .find('\x00') to go to the end of NULL-terminated string.