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?

Hamad Hassan
  • 139
  • 3
  • 13
  • What about `sensorik.cmd('print "sideset %d curve %d"' % (curveID, curveID))`? – Peter Wood Apr 03 '16 at 07:53
  • @PeterWood, it is giving an error. ERROR: , line 77 Unrecognized Keyword: 'print' – Hamad Hassan Apr 04 '16 at 07:20
  • Should the other software understand `print`? – Peter Wood Apr 04 '16 at 07: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. – Hamad Hassan Apr 04 '16 at 07:29
  • `%` interpolates strings, `print` prints the interpolated string. You don't need `print`. – Peter Wood Apr 04 '16 at 07:30
  • 1
    You suggest like sensorik.cmd('sideset %d curve %d' % (curveID, curveID)) ? or – Hamad Hassan Apr 04 '16 at 07:32
  • Yes, no need for `print` – Peter Wood Apr 04 '16 at 07:33
  • Well, I think the question would need improving before I'd answer it. I'm not sure how someone would have the same problem and find this question. The tags aren't relevant other than [tag:python], the problem was a misunderstanding of what role `print` (doesn't) play in creating interpolated strings. – Peter Wood Apr 04 '16 at 07:54
  • ok, I would find a suitable edit so that the question is more general. Thanks for your valuable input, for me it is more clearer now. – Hamad Hassan Apr 04 '16 at 08:06

1 Answers1

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.

Community
  • 1
  • 1
knh190
  • 2,744
  • 1
  • 16
  • 30
  • it is giving the error: ERROR: , line 77 Unrecognized Keyword: 'print' – Hamad Hassan Apr 04 '16 at 07:22
  • @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. – knh190 Apr 05 '16 at 05:45