DGT DGT - 1 year ago 103
Python Question

How to remove ^M

How can I remove the

character from a text file (at the end of line) in a Python script?

I did the following, and there are
at every line-break.

file = open(filename, "w")

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download