attach variable to string
Hi,
sorry for asking many questions, but I'm new to Python.
So, I have an inline-script which sends triggers to the serial port, like this:
port.sendMessage("overview")
These triggers show then up in the logfile of the program that is connected via the serial port (which is an eye-tracker, but I think this doesn't matter for my question).
What I would like to do is: Instread of just "overview" (or "summary" or "draw") I would like to send "overview" and a variable, so that I know which overview (or which summary or which draw) it is. I have these variables defined in a loop and would like to attach them to the string which I send (like port.sendMessage("overview"&var.jar)) but I don't know how I can do that.
Can you give me any tips how to do this or where to look it up?
Thanks a lot!
Pia
Comments
Hi Pia,
Cheers
Thanks a lot!!
Thanks again. Now I have another, very much related, problem.
So some of my variables have this format (in the inline-script):
[color_of_draw[jar_nr]](So the variable names are color_of_draw1, color_of_draw2, and so on.)
I try to send those to the serial port aswell. Here is how I tried that:
color_of_draw_var = "color_of_draw" + str(var.jar_nr) port.sendMessage("Draw Jar" + str(var.jar_nr) + "Draw Marble" + str(var.color_of_draw_var))So, as you see, I tried to create a variable color_of_draw_var which I then use. But it doesn't work. It sais "The variable 'color_of_draw_var' does not exist."
How can I create that variable?
Hi Pia,
you create a variable called
color_of_draw_varand in the next line you use a variable calledvar.color_of_draw_var. Those are not the same, you see?Eduard
Hi Pia, color_of_draw_var (first line of your code) is unequal to var.color_of_draw_var (second line of your code)
Cheers
Thank you! It works (I didn't know that I didn't had to put the ´´var.´´), but I noticed it's not what I wanted.
So, if I do it like this:
color_of_draw_var = "color_of_draw" + var.jar_nr port.sendMessage("Draw Jar" + str(var.jar_nr) + " Draw Marble " + str(color_of_draw_var))It prints for example (if the Jar was 2) color_of_draw2. I see that that makes sense, but I didn't want it to print color_of_draw2 as a text but the contents of my variable called color_of_draw2.
Here are my variables:

And I would like to print the contents of those (to the serial port).
Any idea how I can do that?
Thanks!
Replace:
color_of_draw_var = "color_of_draw" + var.jar_nrWith
color_of_draw_var = exp.get("color_of_draw" + var.jar_nr)Thanks a lot, it works!!