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

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


It's the default behaviour now, so you can simply omit it:

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

More info

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.

Source: 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).

Source: Robert Harvey's answer on "Why is universal newlines mode deprecated in Python?" on Software Engineering