Skip to content

unspecified-encoding (PLW1514)#

Derived from the Pylint linter.

Fix is always available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for uses of open and related calls without an explicit encoding argument.

Why is this bad?#

Using open in text mode without an explicit encoding can lead to non-portable code, with differing behavior across platforms.

Instead, consider using the encoding parameter to enforce a specific encoding. PEP 597 recommends using locale.getpreferredencoding(False) as the default encoding on versions earlier than Python 3.10, and encoding="locale" on Python 3.10 and later.



Use instead:

open("file.txt", encoding="utf-8")