2👍
✅
In Python 2, source files are interpreted as ASCII by default, unless a coding declaration like the one in your question appears at the top of the file.
In Python 3, source files are interpreted as UTF-8 by default (again, unless a coding declaration specifies some other encoding).
Information on the history of this change can be found in PEP 3120: Using UTF-8 as the default source encoding.
There’s no other way to force Python to interpret a source file as an encoding other than the default.
So, you have two choices:
-
Add the coding declaration to every source file which includes non-ASCII characters.
-
Switch to Python 3.
Option 2 is by far the better choice, and will save you a lot of headache in the long run.
Source:stackexchange.com