title: How can I modify the attributes of an SVG file from Python?
body: <p>I have an svg file that was generated by the map data-visualisation software 'Kartograph'. It contains a large number of paths representing areas on a map. These paths each have some data fields:</p>
  
  <pre><code>&lt;path d=" ...path info... " data-electorate="Canberra" data-id="Canberra" data-no="23" data-nop="0.92" data-percentile="6" data-state="ACT" data-totalvotes="25" data-yes="2" data-yesp="0.08" id="Canberra"/&gt;
  </code></pre>
  
  <p>So that I don't have to generate a new svg file every time, I want to modify some attributes, such as the number of 'yes' votes, from within python. Specifically, I would like to increment/increase the 'yes' votes value by one (for each execution of the code).</p>
  
  <p>I have tried lxml and have browsed the documentation for it extensively, but so far this code has not worked:</p>
  
  <pre><code>from lxml import etree
  
  filename = "aus4.svg"
  tree = etree.parse(open(filename, 'r'))
  
  for element in tree.iter():
      if element.tag.split("}")[1] == "path":
          if element.get("id") == "Lingiari":
              yes_votes = element.get("data-yes")
              print(yes_votes)
              yes_votes.set(yes_votes, str(int(yes_votes) + 1))
              print(yes_votes)
  </code></pre>
  
  <p>Is python the best tool to use for this task? If so how might I change the above code or start afresh. Apologies for any confusion. I am new to this 'lxml' module and svg files, so I'm a bit lost.</p>