gpt4 book ai didi

Python得到正确的行尾

转载 作者:IT老高 更新时间:2023-10-28 21:41:42 26 4
gpt4 key购买 nike

有没有一种简单的方法可以获取当前操作系统使用的行尾类型?

最佳答案

如果您正在对以文本模式打开的文件进行操作,那么您是正确的,换行符都显示为“\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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com