Python代码中中文报错问题解决
2015-03-04 19:16
453 查看
http://hi.baidu.com/yanjingtu/blog/item/eaa0c011b8f9ee1db9127be5.html
http://www.python.org/dev/peps/pep-0263/(标准文档)
Python will default to ASCII as standard encoding if no other
encoding hints are given.
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> :
报错:SyntaxError: Non-ASCII character '\xef' in file qbdg.py on line 4, but no encoding declared
解决,在脚本文件开头加上:
#coding=gbk
#coding=utf-8
#-*- coding: UTF-8 -*-
http://www.python.org/dev/peps/pep-0263/(标准文档)
Python will default to ASCII as standard encoding if no other
encoding hints are given.
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> :
报错:SyntaxError: Non-ASCII character '\xef' in file qbdg.py on line 4, but no encoding declared
解决,在脚本文件开头加上:
#coding=gbk
#coding=utf-8
#-*- coding: UTF-8 -*-
相关文章推荐
- Python代码中中文报错问题解决
- 【python3问题解决】python3代码添加中文注释报错
- Python代码中中文报错问题解决
- sqlite3 jdbc、c接口、python接口处理中文时遇到的问题及其解决方法
- 布同 Python中文问题解决方法(总结了多位前人经验,初学者必看)
- MySQLdb中文乱码问题的解决(Python)
- 解决Eclipse +pydev 中python import 代码提示错误问题
- java代码中实现字符编码转换(解决中文乱码问题)
- BeautifulSoup中文乱码解决问题 python 爬虫 乱码
- JSP 文件 下载 代码 (不使用 jsp smart upload 组件) 解决中文名 问题
- 吐血解决python中文写入文件问题
- Python学习笔记(二)--解决中文的问题
- JSP 文件下载的相对完整代码(解决中文问题和Weblogic报错)
- [再加工]XMLSocket(服务器+客户端)代码,包含解决中文问题
- vb.net从DataGridView复制到Excel.代码实现,解决中文乱码问题 (转载+亲自实践)
- 布同:如何解决Python中文问题(总结了多位前人经验,初学者必看)
- 崩溃,source Insight显示linux代码中文注释乱码问题,以及很傻很天真的解决方法
- python邮件发送(带附件,解决中文乱码问题)
- django+httpd+mod_pythonurl存在中文路径问题解决
- Python 使用 UTF-8 编码,python代码中包含中文时执行脚本错误的解决办法。