如何从下面的文本中提取 WESTBOUNDINGCOORDINATE、NORTHBOUNDINGCOORDINATE、EASTBOUNDINGCOORDINATE 和 SOUTHBOUNDINGCOORDINATE?但是,所有元文件都没有在同一行中的文本,例如,罚款一个
在第 2 行有 WESTBOUNDINGCOORDINATE,但文件 2 在第 4 行有它。请帮助...
GROUP = BOUNDINGRECTANGLE
OBJECT = WESTBOUNDINGCOORDINATE
NUM_VAL = 1
VALUE = 80.8290376770946
END_OBJECT = WESTBOUNDINGCOORDINATE
OBJECT = NORTHBOUNDINGCOORDINATE
NUM_VAL = 1
VALUE = 39.9999999964079
END_OBJECT = NORTHBOUNDINGCOORDINATE
OBJECT = EASTBOUNDINGCOORDINATE
NUM_VAL = 1
VALUE = 104.443461525786
END_OBJECT = EASTBOUNDINGCOORDINATE
OBJECT = SOUTHBOUNDINGCOORDINATE
NUM_VAL = 1
VALUE = 29.9999999973059
END_OBJECT = SOUTHBOUNDINGCOORDINATE
END_GROUP = BOUNDINGRECTANGLE
我的代码:
metafiles = glob.glob("D://*.txt")
for f in metafiles:
with open (f, 'r') as infile:
lines = infile.readlines()
WESTBOUNDINGCOORDINATE = lines[4][29:45]
print (WESTBOUNDINGCOORDINATE)
问题是 WESTBOUNDINGCOORDINATE 值并不总是在同一行。