I have this:
rotValues = '[rx='+ rotx + ',' + "ry=" + roty +"]"
It gives me the error shown in the title, help please!
You are getting this error because you are trying to concatenate a string with floats. Python, being a strongly typed language will not allow that. Therefore, you have to convert the rotx
and roty
values to strings as follows:
rotValues = '[rx='+ str(rotx) + ',' + "ry=" + str(roty) +"]"
If you want your values (rotx
and roty
) to have a certain precision in decimal points, you can do:
rotValues = '[rx='+ str(round(rotx,3)) + ',' + "ry=" + str(round(roty,3)) +"]"
>>> rotx = 1234.35479334
>>> str(round(rotx, 5))
'1234.35479'
Another (and much better way) of doing this is to use the
str.format
method:You can also specify the precision using
format
: