python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
2017-09-15 13:57
513 查看
近来写课件实例,函数与过程返回值时,运行遇到如下问题
SyntaxError: Non-ASCII character'/xe6'。代码如下:
#无返回值函数hello(相当于过程)
def hello():
print 'helloworld!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return['xyz',10000,-98.6]
def bar():
print 'helloworld2!'
return'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
调试,查看由于第一行代码都是中文的注释,中文会出现乱码。经过查阅,找到解决方法,即在代码开始的第一行添加如下一条语句:
# This Python file uses the followingencoding: utf-8
或添加语句为:
# encoding: utf-8
即可解决中文编码问题
最终的代码如下:
# This Python file uses the following encoding: utf-8
#无返回值函数hello(相当于过程)
def hello():
print 'helloworld!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return['xyz',10000,-98.6]
def bar():
print 'helloworld2!'
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 'helloworld!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return['xyz',10000,-98.6]
def bar():
print 'helloworld2!'
return'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
调试,查看由于第一行代码都是中文的注释,中文会出现乱码。经过查阅,找到解决方法,即在代码开始的第一行添加如下一条语句:
# This Python file uses the followingencoding: utf-8
或添加语句为:
# encoding: utf-8
即可解决中文编码问题
最终的代码如下:
# This Python file uses the following encoding: utf-8
#无返回值函数hello(相当于过程)
def hello():
print 'helloworld!'
#有返回值函数foo
#有返回值函数far,并输出print.其中bar函数中返回元组(元组语法不一定需要带圆括号)
def foo():
return['xyz',10000,-98.6]
def bar():
print 'helloworld2!'
return'abc',[42,'python'],"Guido"
res = hello()
#调用res时,返回none。无返回值
print res
#调用aTuple时返回 return内容,及返回值内容
aTuple = bar()
print aTuple
相关文章推荐
- python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
- python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
- python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法 推荐
- sublime运行Python报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- python 出现错误 SyntaxError: Non-ASCII character 的解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- 在NPP运行Python报错:SyntaxError: Non-ASCII character '\xe5' in file的解决方法
- Python出现"Non-ASCII character '\xe6' in file"错误解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python编译出现错误SyntaxError: Non-ASCII character '\xe7' 时解决方法
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- Python编码错误的解决办法SyntaxError: Non-ASCII character '\xe5' in file
- Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法
- python错误解决:SyntaxError: Non-ASCII character '\xd3' in file crawler.py