Getting d-lines can be reduced to a couple of lines using svgpathtools , the rest can be done using regular expressions.
from svgpathtools import svg2paths paths, attributes = svg2paths('some_svg_file.svg')
paths is a list of svgpathtools Path path objects (containing only curve information, without colors, styles, etc.). attributes - a list of attributes dictionary objects.
Suppose the path you are interested in is the first (0th) specified in your SVG, and then extract only the d-string that you can use:
d = attributes[0]['d'] # d-string from first path in SVG # Now for some regular expressions magic import re split_by_letters = re.findall('[AZ|az][^AZ|az]*', d) split_as_you_want = [] for x in split_by_letters: nums = x[1:].replace(',',' ').split() # list of numbers after letter for k in range(len(nums) // 2): split_as_you_want.append([x[0]] + [nums[k]] + [nums[k+1]]) print split_as_you_want
I have not converted the numbers to strings here, since how you want to do this depends on whether they are always integers and whether you care to keep them that way. For most purposes, this can be done as follows: "nums = ...".
for k, n in enumerate(nums): try: nums[k] = int(n) except ValueError: nums[k] = float(n)
source share