simple string question
Sean DiZazzo
half.italian at gmail.com
Mon Sep 7 01:57:16 EDT 2009
On Sep 6, 10:29 pm, "jwither" <jwit... at sxder4kmju.com> wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
>
> James Withers
I believe "\n" is a newline. As is "\r\n" and "\r". Choose your
demon.
mystring = mystring.replace("\n", demon)
FYI. If you are reading from a file, you can iterate over the lines
without having to worry about newlines:
fi = open(path_to_file, 'r')
for line in fi:
process_line(line)
~Sean
More information about the Python-list
mailing list