input variable into python call subprocess

夙愿已清 提交于 2019-12-12 02:38:50

问题


I have a small python snippet that calls a larger program (I did not write the larger one).

call(['function1', file1,  file2,  'data.labels=abc, xyz'])

The above works.

input ='abc, xyz'

Now I want to input "abc, xyz" as a variable holding this value

call(['function1', file1,  file2,  'data.labels=input'])

but it does not work.

How can I pass a variable value into variable data.labels within call subprocess.


回答1:


call(['function1', file1,  file2,  'data.labels=%s' % input])



回答2:


Or

call(['function1', file1,  file2,  'data.labels=' + input)

If for some reason, input is not a string.

call(['function1', file1,  file2,  'data.labels=' + str(input) )



回答3:


Another way to do the same:

call(['function1', file1,  file2,  'data.labels={0}'.format(input)])


来源:https://stackoverflow.com/questions/25752837/input-variable-into-python-call-subprocess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!