Python中文显示问题:Non-ASCII character

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了~

菜鸟真菜啊~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值