How can I remove the ^M character from a text file (at the end of line) in a Python script?
I did the following, and there are ^M at every line-break.
file = open(filename, "w")
file.write(something)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re writing the file, you should specify
open(filename, "wb"). That way, you’ll be writing in binary mode, and Python won’t attempt to determine the correct newlines for the system you’re on.