如何在 geolocator.reverse() 函数中放置变量?

问题描述

我设置了 lat1lng1。当我尝试时:

location = geolocator.reverse('lat1','lng1')

它给了我错误

类型错误

Traceback (most recent call last)
<ipython-input-65-bef81ce5884b> in <module>
----> 1 location = geolocator.reverse('lat1','lng1')

TypeError: reverse() takes 2 positional arguments but 3 were given

当我在没有“,”的情况下尝试时,它给了我一个语法错误

解决方法

您可以使用以下代码:

location = geolocator.reverse("{},{}".format(lat1,lng1))

上面的代码将变量格式化为 .reverse() 方法的字符串。