split text file with x0Dx0A

O

ownowl

Hello

beginer under python, I have a problem to get lines in a text file.
lines have inside the \n (x0A) char, and le readline method split the
line at this char too (not only at x0Dx0A).
for resume, I want to split a file to lines with only those chars : x0Dx0A

A idea ?
thank's
Olivier
 
F

Fredrik Lundh

ownowl said:
beginer under python, I have a problem to get lines in a text file.
lines have inside the \n (x0A) char, and le readline method split the
line at this char too (not only at x0Dx0A).

that's not a very clever design, at least if you plan to read the files
from C or compatible languages...
for resume, I want to split a file to lines with only those chars : x0Dx0A

A idea ?

the easiest way to do this is to open the file in binary mode, gobble up
the entire file, and split it yourself:

for line in open(filename, "rb").read().split("\r\n"):
...

</F>
 
O

ownowl

Fredrik Lundh a écrit :
:




that's not a very clever design, at least if you plan to read the files
from C or compatible languages...




the easiest way to do this is to open the file in binary mode, gobble up
the entire file, and split it yourself:

for line in open(filename, "rb").read().split("\r\n"):
...

</F>

great
thank's
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top