0

使用我从以下链接获得的代码:http: //python-overpy.readthedocs.org/en/latest/example.html我想输入我已经获得的变量而不是直接输入它们,如下所示:

import overpy
api = overpy.Overpass()
result = api.query("node(min_lat,min_lon,max_lat,max_lon);out;")
len(result.nodes)

变量 min_lat 等是浮点类型。这是我得到的错误:

overpy.exception.OverpassBadRequest: Error: line 1: parse error: Unknown query clause 
Error: line 1: parse error: ')' expected - 'min_lat' found. 
Error: line 1: parse error: An empty query is not allowed 
Error: line 1: parse error: Unknown type ";" 
Error: line 1: parse error: An empty query is not allowed 

非常感谢任何帮助,因为我对所有这些都非常困惑和陌生,谢谢!

4

1 回答 1

1

您实际上是在将查询发送node(min_lat,min_lon,max_lat,max_lon);out;到 Overpass API,min_lat等等都没有改变。

要填充变量,您可以使用字符串替换:

"node(%s, %s, %s, %s);out;" % ( min_lat, min_lon, max_lat, max_lon )

%s替换为您在括号中提供的变量。

import overpy
api = overpy.Overpass()

min_lat = 50.745
min_lon = 7.17
max_lat = 50.75
max_lon = 7.18

query = "node(%s, %s, %s, %s);out;" % ( min_lat, min_lon, max_lat, max_lon )
result = api.query(query)

print query
print len(result.nodes)
于 2016-01-30T15:41:49.507 回答