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是個酷玩意
溫故知新
載入中…
歷史上的今天..
- 兒時回憶–無敵鐵牛! - 2005







最新回應