Python3: Reading a text/binary mixed file

Paulo da Silva p_s_d_a_s_i_l_v_a_ns at netcabo.pt
Tue Mar 10 18:48:17 EDT 2015


On 10-03-2015 12:41, random832 at fastmail.us wrote:
> On Tue, Mar 10, 2015, at 00:01, Paulo da Silva wrote:
>> For .pnm photo files I read the entire file (I needed it in memory
>> anyway), splited a copy separated by b'\n', got the headers stuff and
>> then used the original remaining bytes as the photo pixels.
>> But this is very tricky! I am on linux, but if I ran this program on
>> windows I needed to change it to "eat" also the '\r'.
> 
> Why? The file is the same file. If the .pnm format is allowed to have a
> '\r' there, you're just as likely to have to deal with it in Linux.
> 
Yes, but I'm creating and reading the files in linux.
.pmm is just an example I'm facing now but my question was more general.

According to the response of Cameron, this can be handled with 'strip'.




More information about the Python-list mailing list