open "U" 模式的非弃用版本是什么

What is the non deprecated version of open "U" mode

我正在尝试使用 python 读取文本文件:

with open("Keys.txt","rU") as csvfile:

但是这会产生折旧警告。

DeprecationWarning: 'U' mode is deprecated

text/csv 文件的这种访问模式的非弃用版本是什么。

这是现在的默认行为,因此您可以简单地忽略它:

with open("Keys.txt", "r") as csvfile:

更多信息

There is an additional mode character permitted, 'U', which no longer has any effect, and is considered deprecated. It previously enabled universal newlines in text mode, which became the default behaviour in Python 3.0. Refer to the documentation of the newline parameter for further details.

来源: open() - Python 3.7.4 documentation

The open() function in the Python 3 library has a newline argument. Setting it to None enables universal newlines. This is the accepted way to do it, rendering the mode='U' argument redundant.

Use newline=None to enable universal newlines mode (this is the default).

来源Robert Harvey's answer 关于“为什么在 Python 中不推荐使用通用换行符模式?”关于软件工程