Ask coding questions

← Back to all posts
[Python] Is there any why to make \n not go to next line in a string?
MisledWater79 (0)

I have some code that writes to a .txt file and in the string im sending over it has \n and it causes it to go to the next line, I dont wont this so how could i go about making it not go to the next line?

Comments
hotnewtop
ch1ck3n (2373)

mystring.replace("\n", "") is maybe what you want and mystring is the string

MisledWater79 (0)

@ch1ck3n Well i dont want to remove them, I want it to send a string to the file with the \n in it but just not make it go to a new line.

ch1ck3n (2373)

@MisledWater79 mystring.replace("\n", "\\n")