preload
Nov 05

tchinese.py

#!/bin/python
print "Python臬瑞拇"
python tchinese.py
SyntaxError: Non-ASCII character '\xe6' in file tchinese.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

航炊閮臭葉蝯圈蝭蝡嚗PEP 0263 — Defining Python Source Code Encodings
銝剜堆

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

Example:

#!/bin/python
# -*- coding: utf-8 -*-
print "Python臬瑞拇"

Result:

Python臬瑞拇
Tagged with: