when displaying a python string in console how do I make it parse the \r\n?

Red Squirrel

No Lifer
May 24, 2003
69,818
13,393
126
www.anyf.ca
I really don't know how to search for this, not finding much on google. so say I have a string like this:

Code:
This is a line \r\nThis is another line

I want to print it to the console, and I want it to show up as:

Code:
This is a line
this is another line

Rather than the literal string.

I'm working with XML stuff and for debug purposes I have it print out the raw XML but it's all bunched up in one line and hard to read I just want it to actually "parse" the \r\n instead of actually displaying it.
 

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
Python:
text = "This is a line \r\nThis is another line"
list = text.split("\r\n")
print(*list, sep='\n')
 
Last edited:

Red Squirrel

No Lifer
May 24, 2003
69,818
13,393
126
www.anyf.ca
Thanl's that worked, except I had to do "\\r\\n" in the split command so it detects the literal \ I thought there was maybe a simpler way but this works.
 

mxnerd

Diamond Member
Jul 6, 2007
6,799
1,103
126
except I had to do "\\r\\n" in the split command so it detects the literal \
That's weird, single backslash worked for me. I tried double backslashes and it worked too.

==

Additional useful info:

 
Last edited: