解决Python代码编码问题 SyntaxError: Non-UTF-8 code starting with '\xc1'
本文转载自:http://blog.csdn.net/wyb_hardworking/article/details/19562971
程序中出现中文,运行的时候出现如下错误:
SyntaxError: Non-UTF-8 code starting with '\xc1' in file C:\...\xxx.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
导致出错的根源就是编码问题。
解决方案是:
在程序最上面加上:
# coding=gbk
这样程序就可以正常运行了。
解决Python代码编码问题 SyntaxError: Non-UTF-8 code starting with '\xc1'的更多相关文章
- Python代码编码规范
目录 1. Introduction 介绍 2. A Foolish Consistency is the Hobgoblin of Little Minds 尽信书,则不如无书 3. Code la ...
- Python中添加中文注释报错SyntaxError: Non-UTF-8 code starting with '\xc1'
问题:在文本编辑器中编辑Python文件时添加中文注释,运行python文件时报错.SyntaxError: Non-UTF-8 code starting with '\xc1' 解决方法:在文本开 ...
- SyntaxError: Non-UTF-8 code starting with '\xc1'
问题描述: 运行Python脚本,报错了:SyntaxError: Non-UTF-8 code starting with '\xc1' 不是不支持中文,是脚本的编码格式设置不正确. 在python ...
- 如何解决python连接数据库编码问题(python传数据到mysql乱码)'ascii' codec can't encode _mysql_exceptions.OperationalError: (1366, "Incorrect string value:?
首先描述下问题: 在使用python计算出结果后将结果插入到mysql过程中,报如下错误.原因很好定位就是编码的问题.那么到底是编码哪里出了问题了呢? 报错如上: 排查顺序: 第一:python的编 ...
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息: SyntaxError: Non-ASCII character '\xe5' in file ******* 解决方法: py ...
- 解决python代码中含有中文报错
python中写入中文时报错如下图所示: 依照网上解决方法:在py文件中加入:#encoding=utf-8 然后继续报错如下图所示: 解决方法: 在py文件中加入: import sysreload ...
- 怎么解决syntaxerror:non-utf-8 code starting with \xc4'in file
怎么解决syntaxerror:non-utf-8 code starting with \xc4'in file 首行增加,已测试可用. # coding=gbk 程序中出现中文,运行的时候 ...
- Python字符编码补充
字符编码: Python字符编码贯穿Python学习的始终,现在应用的是Python2中字符编码的问题是很多的. 这次是要彻底解决Python字符编码的问题!!! 1 字符编码的发展过程: 1 .AS ...
- 【翻译】Python PEP8编码规范(中文版)
原文链接:http://legacy.python.org/dev/peps/pep-0008/ item detail PEP 8 Title Style Guide for Python Code ...
随机推荐
- 解决Github Desktop Repo publish 失败问题
参考: src refspec master does not match any when pushing commits in git Github上传项目步骤和常见问题 Trying to gi ...
- poj 2828 Buy Tickets 树状数组
Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so ...
- ResourceNotFound: rgbd_launch
Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking ...
- Kotlin中常量和静态方法
常量 Java中: class StaticDemoActivity { public static final String LOAN_TYPE = "loanType"; pu ...
- K-Means & Sequential Leader Clustering
2017-12-31 19:08:37 k-平均算法源于信号处理中的一种向量量化方法,现在则更多地作为一种聚类分析方法流行于数据挖掘领域.k-means的目的是:把样本划分到k个聚类中,使得每个点都属 ...
- 331. Verify Preorder Serialization of a Binary Tree -- 判断是否为合法的先序序列
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...
- 快速理解 FastCGI、PHP-CGI、PHP-FPM
你(PHP)去和泰国人(web服务器,如 Apache.Nginx)谈生意 你说中文(PHP代码),他说泰语(C代码),互相听不懂,怎么办?那就都把各自说的话转换成英语(FastCGI 协议)吧. 怎 ...
- hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0
Description “Farm Game” is one of the most popular games in online community. In the community each ...
- Constructor vs Object
1. Constructor:是用于创建和初始化类中创建的一个对象的一种特殊方法. constructor([arguments]) { ... } 在一个类中只能有一个名为 “constructor ...
- halcon之共线连接union_collinear_contours_xld
union_collinear_contours_xld 很多时候当我们用edges_sub_pix, threshold_sub_pix 等算子得到边缘后,因为有噪声.物体本身断裂等原因 很多边缘 ...