python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
2015-09-11 12:44
656 查看
来源:http://blog.sina.com.cn/s/blog_5007d1b101018i2j.html
近来写课件实例,函数与过程返回值时,运行遇到如下问题
SyntaxError: Non-ASCII character '/xe6'。代码如下:
#无返回值函数hello(相当于过程)
def hello():
print 'hello world!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return ['xyz',10000,-98.6]
def bar():
print 'hello world2!'
return 'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
调试,查看由于第一行代码都是中文的注释,中文会出现乱码。经过查阅,找到解决方法,即在代码开始的第一行添加如下一条语句:
# This Python file uses the following encoding: utf-8
或添加语句为:
# encoding: utf-8
即可解决中文编码问题
最终的代码如下:
# This Python file uses the following encoding: utf-8
#无返回值函数hello(相当于过程)
def hello():
print 'hello world!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return ['xyz',10000,-98.6]
def bar():
print 'hello world2!'
return 'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
近来写课件实例,函数与过程返回值时,运行遇到如下问题
SyntaxError: Non-ASCII character '/xe6'。代码如下:
#无返回值函数hello(相当于过程)
def hello():
print 'hello world!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return ['xyz',10000,-98.6]
def bar():
print 'hello world2!'
return 'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
调试,查看由于第一行代码都是中文的注释,中文会出现乱码。经过查阅,找到解决方法,即在代码开始的第一行添加如下一条语句:
# This Python file uses the following encoding: utf-8
或添加语句为:
# encoding: utf-8
即可解决中文编码问题
最终的代码如下:
# This Python file uses the following encoding: utf-8
#无返回值函数hello(相当于过程)
def hello():
print 'hello world!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return ['xyz',10000,-98.6]
def bar():
print 'hello world2!'
return 'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
相关文章推荐
- python相关文件方法
- chapter4 python技巧
- python元组的修改和删除
- 【Python之旅】第二篇(三):基于列表处理的购物清单程序
- 【Python之旅】第二篇(三):基于列表处理的购物清单程序
- Python六大开源框架对比:Web2py略胜一筹
- 用python加载3ds max场景设置相关参数,渲染,保存输出图,最后退出3dsmax软件
- 【Python基础】Python面向对象 - 5 - super()函数
- python对象地址学习
- python 遇到 syntaxerror: non-ascii character有关问题
- 用Python学习统计学基础-2
- python内存使用情况
- Python异步IO的未来(从Web后端开发的角度)
- 15个最受欢迎的Python开源框架
- Python代码的运行机制
- [译]如何定义python源文件的文件编码
- 【Python基础】Python面向对象 - 4 - 定制类的特殊方法
- python 标准库urllib2的使用细节
- Python使用matplotlib和pandas实现的画图操作【经典示例】
- python脚本 从wooyun.org获取厂商域名