Skip to main content
 首页 » 编程设计

python之当我将它粘贴到 vim 中时,为什么会出现语法错误

2025年05月04日12jirigala

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详情

请您参考如下方法:

这可能是一个间距问题(\xc2 是一个空格字符),尝试仅使用空格重新缩进,别无其他。您还可以将 # -*- coding:utf-8 -*- 放在文件的顶部,看看是否有帮助。