[Tutor] Standardizing on Unicode and utf8

Kent Johnson kent37 at tds.net
Wed Feb 25 20:26:14 CET 2009


On Wed, Feb 25, 2009 at 12:46 PM, Thorsten Kampe
<thorsten at thorstenkampe.de> wrote:
> * spir (Fri, 20 Feb 2009 13:02:59 +0100)

>> > Use the header: # -*- coding: utf8 -*-
>>
>> You don't even need fancy decoration:
>>
>> # coding: utf-8
>>
>> is enough.
>
> Sure? Never heard of that. Interesting...

>From PEP 263 (http://www.python.org/dev/peps/pep-0263/):
    To define a source code encoding, a magic comment must
    be placed into the source files either as first or second
    line in the file, such as:

          # coding=<encoding name>

    or (using formats recognized by popular editors)

          #!/usr/bin/python
          # -*- coding: <encoding name> -*-

    or

          #!/usr/bin/python
          # vim: set fileencoding=<encoding name> :

    More precisely, the first or second line must match the regular
    expression "coding[:=]\s*([-\w.]+)".

The -*- style is also recognized by some editors.

Kent


More information about the Tutor mailing list