Github, why does my python code have ^M and no new lines?

Viewed 626

The code in my editor shows up fine but whenever I push it to Github it's just being displayed in one line, I have never had this issue before, could this be python related?

code in github

Edit: When the file is viewed as raw it seems to be fine.

1 Answers

You editor is using a CR (carriage-return). That's the ^M you see in Github. This is a Windows application way of marking a new line, rather than the Linux \n newline. It is somewhat surprising that this isn't a \r\n (so you would see new lines, but all lines ending with ^M) since that what Windows stuff usually does - your editor seems to only put in \r, which Linux just ignores and that's what Github is using to display your file.

The raw file is handled by the browser which knows how to handle \r, hence, it looks right.

To fix this use a search and replace from \r to \n in an editor capable of it. You should probably configure your editor to use \n, or switch editor.

Related