Python3: Reading a text/binary mixed file

Dave Angel davea at davea.name
Mon Mar 9 20:55:44 EDT 2015


On 03/09/2015 08:45 PM, Paulo da Silva wrote:
> Hi!
>
> What is the best way to read a file that begins with some few text lines
> and whose rest is a binary stream?
>
> As an exmaple ... files .pnm.
>
> Thanks for any comments/help on this.
>

In which version of Python?  there's a huge difference between 2.x and 3.x

Generally speaking, you can treat a piece of a binary (input) file as an 
encoded string, so you want to open the file as binary, locate the part 
that's text, and then explicitly decode the string from that.


-- 
DaveA



More information about the Python-list mailing list