为什么我在vim中粘贴这个会出现语法错误?
def latlong_distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
radius = 6371
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1) a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = radius * c
return d * 1000
出现了一个语法错误:在文件 /tools.py 的第65行发现了一个非ASCII字符 '\xc2',但是没有声明编码方式。想了解更多信息,可以查看这个链接:http://www.python.org/peps/pep-0263.html
2 个回答
1
我稍微修改了一下那个代码:
dlon = math.radians(lon2-lon1) a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
应该像这样分成两行:
dlon = math.radians(lon2-lon1)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
我试过了,没有出现任何错误。你能把那个文件附上来吗?
7
这可能是空格的问题(\xc2是一个空格字符),试着只用空格重新调整缩进,不要用其他的东西。你还可以在文件的最上面加上# -*- coding:utf-8 -*-
,看看这样是否有帮助。