I am using python to generate command list for another software interface. Using command
sensorik.cmd('list curve')
will put the text
list curve
in that interface and it lists all curves in that program up to that point. Now I have to introduce a loop of commands, here is a sample
sideset 1 curve 1
sideset 2 curve 2
sideset 3 curve 3
I used
for curveID in range (1, 4):
print "sideset %d curve %d" % (curveID, curveID)
sensorik.cmd('print "sideset %d curve %d" % (curveID, curveID)')
sensorik.cmd('sideset %d curve %d" % (curveID, curveID)')
This however, doesnot work and the interface gets the command
print "sideset %d curve %d" % (curveID, curveID)
and it does print the required text on the shell prompt but does not parse it to the software when used in sensorik.cmd. Instead the software gets
print "sideset %d curve %d" % (curveID, curveID)
print "sideset %d curve %d" % (curveID, curveID)
print "sideset %d curve %d" % (curveID, curveID)
any suggestions?
asked Apr 3, 2016 at 7:48
Hamad Hassan
1393 silver badges13 bronze badges
1 Answer 1
Why not:
cmd = 'print "sideset %d curve %d" %% (curveID, curveID)' % (curveID, curveID)
sensorik.cmd( cmd )
You need %% to escape percent symbol as here pointed out.
answered Apr 3, 2016 at 7:54
knh190
2,8921 gold badge21 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Hamad Hassan
it is giving the error: ERROR: <stdin>, line 77 Unrecognized Keyword: 'print'
knh190
@HamadHassan It's not the question (you asked) about constructing the command. You make what you need. ex. use
echo for bash instead of print. Or just remove if it shouldn't be used.lang-py
sensorik.cmd('print "sideset %d curve %d"' % (curveID, curveID))?print?