Mon, 17 Apr 2017 22:56:39 +0300
Aluemuotoja
#!/usr/bin/env python3 from pprint import pprint with open('alueet.gmp') as file: data = file.read() shapes = {} polygons = data.split('@')[1] for polygon in polygons.splitlines(): polygon = polygon.split('^') nimi = polygon[2].rsplit('>', 1)[1] coordinates = [] for point in polygon[3].split('~'): x, y = point.split(',') coordinates.append((float(x), float(y))) shapes[nimi.strip().replace('\u200b', '')] = coordinates pprint(shapes)