split text file with x0Dx0A

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ownowl

    #1

    split text file with x0Dx0A

    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
  • Fredrik Lundh

    #2
    Re: split text file with x0Dx0A

    "ownowl" wrote:
    [color=blue]
    > 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).[/color]

    that's not a very clever design, at least if you plan to read the files
    from C or compatible languages...
    [color=blue]
    > for resume, I want to split a file to lines with only those chars : x0Dx0A
    >
    > A idea ?[/color]

    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().sp lit("\r\n"):
    ...

    </F>



    Comment

    • ownowl

      #3
      Re: split text file with x0Dx0A

      Fredrik Lundh a écrit :[color=blue]
      > "ownowl" wrote:
      >
      >[color=green]
      >>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).[/color]
      >
      >
      > that's not a very clever design, at least if you plan to read the files
      > from C or compatible languages...
      >
      >[color=green]
      >>for resume, I want to split a file to lines with only those chars : x0Dx0A
      >>
      >>A idea ?[/color]
      >
      >
      > 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().sp lit("\r\n"):
      > ...
      >
      > </F>[/color]

      great
      thank's

      Comment

      Working...