simple string question

Sean DiZazzo half.italian at
Mon Sep 7 07:57:16 CEST 2009

On Sep 6, 10:29 pm, "jwither" <jwit... at> 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

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:


More information about the Python-list mailing list