Search notes:

PEP 263 - Defining Python Source Code Encodings

PEP 263 specifies that a magic comment can be placed in the first or second line of a Python source file to specify the encoding of the file.
In order for a line to be recognized as such a magic comment, it must match the regular expression ^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+), for example
# coding=latin-1
or
# -*- coding: utf-8 -*-
or the following line (which simultaneously sets a vim option):
# vim: fileencoding=iso-8859-15

See also

Experiments with source file encoding in Python.
PEPs 686 and 3120
A small list of other interesting PEPs

Index