I have a line of text. A line contains several newline characters. I want to create a csv that includes this line, so I can import it into excel. However, because of this, I believe that I need to convert all newlines to carriage returns and wrap the text in quotation marks.
However, when I try to convert a small amount of text, I get the following results:
Before
>>> abc = "\nA\nB\nC\nD\nE\nF\nG\n\n" >>> print abc A B C D E F G
After
>>> xyz = abc.replace('\n','\r') >>> xyz '\rA\rB\rC\rD\rE\rF\rG\r\r' >>> print xyz G
Any ideas what I'm doing wrong?
source share