从lis中提取精确值

2024-09-28 01:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从中提取经纬度-

Feature(place='12km SSE of Volcano, Hawaii', long=-155.2005, lat=19.3258333, depth=6.97, mag=5.54)

部分代码如下

lrgst = features[0]
print ('\n',lrgst)
plt.bar(y_pos, magn)
plt.xticks(y_pos, loc)
plt.ylabel('Magnitude')
plt.show()


features = list(get_info()) #Storing our json information into a list 'Features'

Tags: ofposplacepltlongfeaturelistsse
2条回答

假设“features”是一个条目列表,如给出的示例所示,此解决方案将起作用:

features = ["Feature(place='12km SSE of Volcano, Hawaii', long=-155.2005, lat=19.3258333, depth=6.97, mag=5.54)"]

def find(string, char_before, char_after):
    start = string.find(char_before) + len(char_before)
    end = string[start:].find(char_after) + start
    return string[start:end]

long = find(features[0], 'long=', ', ')
lat = find(features[0], 'lat=', ', ')

print(lat + ', ' + long)

    19.3258333, -155.2005

我想用正则表达式提取。。。但有些东西不起作用

如果这奏效了,那么亚历克斯的问题就可以解决了

为什么不匹配

place="12km SSE of Volcano, Hawaii', long=-155.2005, lat=19.3258333, depth=6.97, mag=5.54"

a1=re.match("r(long=)([\-\d\.]*)",place)
if a1:
     print (a1.groups(1))

相关问题 更多 >

    热门问题