Posts tagged with carriage return

Remove DOS newlines from Python files

September 17th, 2008

I’ve been working on a few python files in WIndows and then moving them to Linux but whenever I try to run them I get an error about ‘directory not found’.

I soon discovered that the Windows carriage return messes up the files for Linux so we need to remove them all. If you open the offending file using vi you’ll see lots of ^M characters spread through the file. Fortunately these are pretty easy to remove using vi. Open the file in vi, press escape so we can enter a command, type this command press enter and save the file.

%s/^M/ /g

It’s very important that you create the ^M character by typing alt+v then press m while still holding down alt+v, do not paste straight from this page.

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Switch to our mobile site