Search code examples
pythonparameter-passingvisa

Passing more than two sys.argv in Python


I have a small question in passing two or more sys.argv arguments in Python. I do it using following code.

from visa import *
import sys
inst = instrument(sys.argv[1])
inst.write("*rst; status:preset; *cls")
inst.write("voltage:UNIT Vrms")
inst.write("apply:SIN %s %s" % sys.argv[2] % sys.argv[3])

But this code does not generate any answer.

But if I pass the same code with values embedded using the code

from visa import *
import sys
inst = instrument("USB0::0x164E::0x13EC::TW00008555")
inst.write("*rst; status:preset; *cls")
inst.write("voltage:UNIT Vrms")
inst.write("apply:SIN 1000, 0.5")

I get the result.

Is there something I am missing? Any help would be very useful to pass more than two sys.argv's in Python.


Solution

  • Probably the string formatting is not good, you should try:

    inst.write("apply:SIN %s %s" % (sys.argv[2], sys.argv[3]))
    

    also in the second snippet there is an additional comma so maybe:

    inst.write("apply:SIN %s, %s" % (sys.argv[2], sys.argv[3]))