Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python svgwrite can't add class attribute?

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

like image 511
ueke Avatar asked Dec 08 '25 14:12

ueke


1 Answers

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'))
like image 146
Robert Longson Avatar answered Dec 10 '25 04:12

Robert Longson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!