Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个小脚本,需要在 Windows 和 Linux 甚至 Mac 上读写文本文件。该脚本将被所有可能所有这些平台(当然是 Windows)上的用户使用,并且可以互换使用 - 因此X在 Windows 上写入文件的用户可以使用该脚本在 Linux 上读取文件。
X
我应该采取什么预防措施,或者我应该如何实现能够跨各种平台处理行尾的代码?(读写)
或者这不是问题,Python 处理一切?
这不是问题,Python 就是这样聪明。它可以很好地处理跨平台的行尾。
A non-issue is something you don't have to pay any attention to for the rest of your life. That's not the case here, it's all too easy to mess up line-endings in Python, even.
For platform-independent writing, see here
For p-i reading, see here