PEP 263 defines how to declare Python source code encoding. Normally, the first 2 lines of a Python file should start with:
#!/usr/bin/python
# -*- coding: <encoding name> -*-
But I have seen a lot of files starting with:
#!/usr/bin/python
# -*- encoding: <encoding name> -*-
I.e., it says encoding
rather than coding
.
How should the file encoding be declared?
Please use "SyntaxError: Non-ASCII character ..." or "SyntaxError: Non-UTF-8 code starting with ..." trying to use non-ASCII text in a Python script to close duplicate questions about syntax errors resulting from a missing or faulty encoding declaration. This question, on the other hand, is the canonical for questions about how the declaration is written and whether it is necessary.