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):