您的位置:首页 > 编程语言 > Python开发

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 -*-
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: