how to do reading of binary files?

Diez B. Roggisch deets at nospam.web.de
Fri Jun 8 08:07:36 EDT 2007


jvdb schrieb:
> Hi all,
> 
> I need some help on the following issue. I can't seem to solve it.
> 
> I have a binary (pcl) file.
> In this file i want to search for specific codes (like <0C>). I have
> tried to solve it by reading the file character by character, but this
> is very slow. Especially when it comes to files which are large
> (>10MB) this is consuming quite some time.
> Does anyone has a hint/clue/solution on this?

What has the searching to do with the reading? 10MB easily fit into the 
main memory of a decent PC, so just do


contents = open("file").read() # yes I know I should close the file...

print contents.find('\x0c')

Diez



More information about the Python-list mailing list