简体   繁体   中英

input variable into python call subprocess

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.

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

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) )

另一种方法是:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM