2

我正在编写一个小脚本,需要在 Windows 和 Linux 甚至 Mac 上读写文本文件。该脚本将被所有可能所有这些平台(当然是 Windows)上的用户使用,并且可以互换使用 - 因此X在 Windows 上写入文件的用户可以使用该脚本在 Linux 上读取文件。

我应该采取什么预防措施,或者我应该如何实现能够跨各种平台处理行尾的代码?(读写)

或者这不是问题,Python 处理一切?

4

2 回答 2

3

这不是问题,Python 就是这样聪明。它可以很好地处理跨平台的行尾。

于 2010-12-23T19:58:36.910 回答
1

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

于 2014-07-23T21:27:24.443 回答