Python对中文支持确认够呛!
基本上每个人都遇到过~
俺遇到的更奇特一些~
俺开始学习的时候那个教程作者是在Lilux下开发的~
所以他的例子前面都有两句:
#! /usr/bin/env python
#-*- encoding: utf-8 -*
俺这个学生很习惯性的都复制这两句
开始遇到中文显示也没在意,就不用呗用英文也可以
后来写一个东西的时候必须要用中文
那么问题来了
咋都解决不了
加#-*- coding: gbk -*-也不对
加#-*- coding: utf-8 -*-也不行
都提示错误!
查了下都是说这样就能解决问题的?!什么情况呢?!
后来查到关于编码有这样的描述
More precisely, the first or second line must match the regular
expression "coding[:=]\s*([-\w.]+)". The first group of this
expression is then interpreted as encoding name. If the encoding
is unknown to Python, an error is raised during compilation. There
must not be any Python statement on the line that contains the
encoding declaration.
To aid with platforms such as Windows, which add Unicode BOM marks
to the beginning of Unicode files, the UTF-8 signature
'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well
(even if no magic encoding comment is given).
If a source file uses both the UTF-8 BOM mark signature and a
magic encoding comment, the only allowed encoding for the comment
is 'utf-8'. Any other encoding will cause an error.
看半天原来是第一行#! /usr/bin/env python不能要啊!
去掉后OK了~
菜鸟真菜啊~