python下运行报"SyntaxError: Non-ASCII character '/xe6' "错误解决方法

简介:
+关注继续查看

近来写小样例,函数与过程返回值时,运行遇到如下问题

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
















本文转自hblxp32151CTO博客,原文链接:http://blog.51cto.com/starpoint/1341767,如需转载请自行联系原作者
相关文章
|
11月前
|
前端开发 测试技术
软件测试|selenium+python基础方法封装(二)
软件测试|selenium+python基础方法封装(二)
132 0
软件测试|selenium+python基础方法封装(二)
|
11月前
|
Web App开发 Java 测试技术
软件测试|selenium+python基础方法封装(一)
软件测试|selenium+python基础方法封装(一)
140 0
软件测试|selenium+python基础方法封装(一)
|
11月前
|
Python
Python中Queue.get()方法阻塞,怎么办?
Python中Queue.get()方法阻塞,怎么办?
234 0
|
12月前
|
Python
python的zip对象与enumerate方法
python的zip对象与enumerate方法
99 0
|
12月前
|
Python
python匿名函数与map方法
python匿名函数与map方法
115 0
|
12月前
|
Python
python 中__init__ ,__new__ ,__call__,__del__ 方法
python 中__init__ ,__new__ ,__call__,__del__ 方法
98 0
|
12月前
|
索引 Python
python常用的一些方法
python常用的一些方法
76 0
|
12月前
|
Python Windows
python+windows画图工具--复现别人论文中的colormap 方法2
python+windows画图工具--复现别人论文中的colormap 方法2
python+windows画图工具--复现别人论文中的colormap 方法2
|
12月前
|
Linux Windows Python
python 对陆地数据进行掩膜的两种方法
一般我们分析海洋或者气象相关数据时,经常会绘制散点图分析两重变量之间的相关性。近期在分析数据时,发现有个容易出问题的情况:
python 对陆地数据进行掩膜的两种方法
|
12月前
|
IDE 开发工具 Python
同一个项目中让R和Python无缝工作的五种方法
同一个项目中让R和Python无缝工作的五种方法
93 0
同一个项目中让R和Python无缝工作的五种方法
相关产品
云迁移中心
推荐文章
更多