2

I'm trying to figure out the entire list of possible encodings for a Python source file - that is, encodings that can go in a PEP 263 encoding specification, like # -*- encoding: foo -*-.

Is this list the same as the list given in the documentation for the codecs library, under "Standard Encodings"? If not, where can I find the actual list?

(I know that list is the same as the set of unique values in CPython's /Lib/encodings/aliases.py, or equivalently, the set of filenames in /Lib/encodings/, but again I'm not sure.)

1 Answer 1

0

Yes, the valid encodings for a Python source file are precisely those listed in codecs, at least in CPython.

CPython's tokenizer evaluates the value io.open(<FILE>, "r", -1, <ENCODING>, None, None, False).readline and then uses that function to read lines (source: these lines of CPython's Parser/tokenizer.c). Thus, whichever encodings supported by open() are also supported in the encoding declaration.

See also: Which file encodings are supported for Python 3 source files? and its answers

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.