How come when I paste this in vim, I get syntax errors?
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开发者_如何学C
SyntaxError: Non-ASCII character '\xc2' in file /tools.py on line 65, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
It's probably a spacing issue (\xc2 is a space character), try and reindent using only spaces, nothing else. You can also put # -*- coding:utf-8 -*-
at the top of the file and see if that helps.
I modified that code a little:
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)
should split to two lines like this:
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)
I tried that, and there's no exception raised. Can you attached that file here?
精彩评论