• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

Red Squirrel

No Lifer
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.
 
Python:
text = "This is a line \r\nThis is another line"
list = text.split("\r\n")
print(*list, sep='\n')
 
Last edited:
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.
 
Last edited:
Back
Top