Remove line breaks from strings in python, and wrap the lines in python.
This is written today. Use python to remove linefeeds from strings and write them into files. Check the code online.Replace ("\ n ",""),
After that, it took half a day, but it was still wrong.
The above are the problems I encountered today. The following are the solutions.
The local test is a Windows system, which is officially used on unix servers. I am not very clear about the specific differences between the two line breaks. Therefore, the file written into the string is opened with notepad ++, and the line tail character is displayed (how to use notepad ++ to display the line tail character Baidu). The result is CR, so change the code to replace ("\ r", "") to perfect solution.
Summary:
If the end of a line is CR, replace ("\ r", "") is used ","")
If the line end character is LF, replace ("\ n", "") is used ","")
The following describes how to remove spaces and line breaks in python.
I. Remove Spaces
Strip ()
"Xyz ". strip () # returns "xyz" "xyz ". lstrip () # returns "xyz" "xyz ". rstrip () # returns "xyz" "x y z ". replace ('','') # returns "xyz"
2. replace ("space ","")
UseReplace ("\ n ",""),
Replace the trailing string with the trailing string
Summary
The above section describes how to remove line breaks from strings in python. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!