0

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
9
  • What about sensorik.cmd('print "sideset %d curve %d"' % (curveID, curveID))? Commented Apr 3, 2016 at 7:53
  • @PeterWood, it is giving an error. ERROR: <stdin>, line 77 Unrecognized Keyword: 'print' Commented Apr 4, 2016 at 7:20
  • Should the other software understand print? Commented Apr 4, 2016 at 7:25
  • It should not understand.. it should only get the result generated by our commands.. like print "sideset %d curve %d" % (curveID, curveID) prints the text as sideset 1 curve 1 from curveID=1.. the software should only get this text of sideset 1 curve 1. Commented Apr 4, 2016 at 7:29
  • 1
    You suggest like sensorik.cmd('sideset %d curve %d' % (curveID, curveID)) ? or Commented Apr 4, 2016 at 7:32

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

it is giving the error: ERROR: <stdin>, line 77 Unrecognized Keyword: 'print'
@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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.