python中\n和\r\n的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28228383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between \n and \r\n in python
提问by David542
I have a script that sometimes prints a newline as \n
and sometimes uses \r\n
. What is the difference between the two, and is one preferable over the other?
我有一个脚本,有时会打印换行符\n
,有时会使用\r\n
. 两者之间有什么区别,一个比另一个更可取吗?
采纳答案by Cui Heng
"\n" is the class Unix/linux style for new line. "\r\n" is the default Windows style for line separator. "\r" is classic Mac style for line separator. I think "\n" is better, because this also looks good on windows, but some "\r\n" may not looks so good in some editor under linux, such as eclipse or notepad++. If you are handling some protocols, the "\r\n" is usually required.
"\n" 是用于换行的类 Unix/linux 样式。"\r\n" 是行分隔符的默认 Windows 样式。"\r" 是经典的 Mac 风格的行分隔符。我认为“\n”更好,因为这在windows上看起来也不错,但是有些“\r\n”在linux下的某些编辑器中可能看起来不太好,例如eclipse或notepad++。如果您正在处理某些协议,通常需要“\r\n”。