有没有一种简单的方法可以获取当前操作系统使用的行尾类型?
最佳答案
如果您正在对以文本模式打开的文件进行操作,那么您是正确的,换行符都显示为“\n
”。否则,您正在寻找 os.linesep
.
来自 http://docs.python.org/library/os.html :
os.linesep
The string used to separate (or, rather, terminate) lines on the current platform. This may be a single character, such as '\n' for POSIX, or multiple characters, for example, '\r\n' for Windows. Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.
关于Python得到正确的行尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/454725/