Reputation: 15
I'm using a function from the drawSVG
library: draw.Lines()
. This function is drawing lines between specified points. For example, draw.Lines(x0, y0, x1, y1)
draw a line between the point (x0, y0) and (x1, y1).
My problem is that I would like to draw n lines. To do that, I need to call the function with n arguments (draw.Lines(x0, y1, ... xn, yn)
). Each argument must be a number. I have tried using lists and it didn't work.
I didn't find a way to do it properly. Right now I'm calling the function with the right amount of arguments but I do not like that.
For example if I want to print a square
svg.append(draw.Lines(10,10,100,10,100,100,10,100))
Upvotes: 1
Views: 148
Reputation: 21275
You can use argument unwrapping to pass a list to a function which expects multiple positional arguments.
Your example can be re-written as:
points = [10,10,100,10,100,100,10,100]
svg.append(draw.Lines(*points))
So if you have the end-coordinates for your n lines in a list, you can pass that (with a *
) to the drawLines
function.
Upvotes: 2