1
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

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

5
  • 1
    Did you read the error message? Commented Mar 8, 2011 at 5:30
  • what does this have to do with vim? Commented Mar 8, 2011 at 5:32
  • 3
    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. Commented Mar 8, 2011 at 5:34
  • Yes that's right rafe, thanks. Commented Mar 8, 2011 at 5:39
  • I'll post it as an answer then so we can get this resolved :) Commented Mar 8, 2011 at 5:41

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.