3

I'm trying to correct the following code:

import svgwrite
dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.circle((10, 0), 20 , fill='rgb(0,0,255)', id='rrr', class='#t'))
dwg.save()

I get the following error:

dwg.add(dwg.circle((10, 0), 20 , fill='rgb(0,0,255)', id='rrr', class='#t'))
                                                                    ^
SyntaxError: invalid syntax

Why is that? Apparently svgwrite can't add a class attribute to elements

Robert Longson
  • 118,664
  • 26
  • 252
  • 242
ueke
  • 33
  • 1
  • 4

1 Answers1

7

According to the svgwrite documentation you must add a trailing underscore to attributes which are python keywords. So the correct code would be:

dwg.add(dwg.circle((10, 0), 20 , fill='rgb(0,0,255)', id='rrr', class_='#t'))
Robert Longson
  • 118,664
  • 26
  • 252
  • 242