python 中 \n 和 \r\n 的区别
Difference between \n and \r\n in python
我有一个脚本有时将换行符打印为 \n
,有时使用 \r\n
。两者有什么区别,一个比另一个更可取?
"\n" 是换行的 class Unix/linux 样式。
“\r\n”是行分隔符的默认 Windows 样式。
"\r" 是行分隔符的 classic Mac 样式。
我认为“\n”更好,因为这在 windows 上看起来也不错,但有些“\r\n”在 linux 下的某些编辑器中可能看起来不太好,例如 eclipse 或 notepad++ .
如果您正在处理某些协议,通常需要“\r\n”。
代码
print "\n",
print "\r",
print "\r\n",
为您提供以下十六进制输出
0a 0d 0d 0a
另请参阅答案 here and here。
我有一个脚本有时将换行符打印为 \n
,有时使用 \r\n
。两者有什么区别,一个比另一个更可取?
"\n" 是换行的 class Unix/linux 样式。 “\r\n”是行分隔符的默认 Windows 样式。 "\r" 是行分隔符的 classic Mac 样式。 我认为“\n”更好,因为这在 windows 上看起来也不错,但有些“\r\n”在 linux 下的某些编辑器中可能看起来不太好,例如 eclipse 或 notepad++ . 如果您正在处理某些协议,通常需要“\r\n”。
代码
print "\n",
print "\r",
print "\r\n",
为您提供以下十六进制输出
0a 0d 0d 0a
另请参阅答案 here and here。