简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM