Replace \n with <br />

newline, python, replace, string

Solution

Just for kicks, you could also do

mytext = "<br />".join(mytext.split("\n"))

to replace all newlines in a string with `<br />`.

Problem

I'm parsing text from a file with Python. I have to replace all newlines with `<br />`. I tried this code: ``` thatLine.replace('\n', '<br />') print thatLine ``` But I still see the text with newline after it. Why?

Original source

Related problems