When to use utf8 as a header in py files
python, utf-8
Solution
wherever you need to use in your code chars that aren't from ascii, like:
ă
interpreter will complain that he doesn't understand that char.
Usually this happens when you define constants.
Example: Add into x.py
print 'ă'
then start a python console
import x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "x.py", line 1
SyntaxError: Non-ASCII character '\xc4' in file x.py on line 1,
but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details
Problem
Some source files, from downloaded code, have the following header ``` # -*- coding: utf-8 -*- ``` I have an idea what utf-8 encoding is but why would it be needed as a header in a python source file?