python - forming a string with variable inside

in the following Python scripting:

op(‘serial1’).send(‘s2,2000,3\r’)

What is the syntax for replacing value ‘2000’ with a chop channel value ?

assuming that it’s going to be an integer value (“2000” instead of “2000.0”), it’d be this:

op('serial1').send('s2,%d,3\r' % int(op("thechop")["somechannel"][0]))

thanks! works a charm. I think I understand all the code, except for the [0] at the end. Is that an initializing, arbitrary value for the chop chan ?

CHOP channels are indexed, and the index starts at zero. So when you call

op('constant1')[0]

You’re calling operator named constant1, and the first channel, which is index 0. If it was

op('constant1')[2]

It would grab the 3rd channel in the constant.

In my example, the [0] selects the first sample out the channel named “somechannel”. Each channel in a CHOP is effectively an array of values (even if it’s just an array that has 1 value in it), so this grabs the first of those values:

op("thechop")["somechannel"][0]

and this grabs the second sample from that same channel:

op("thechop")["somechannel"][1]

got it!. I knew that but forgot.
“repetition teaches” - Netochka Nezvanova/nato.0+55