A question about a list and subprocess.check_call()

MRAB python at mrabarnett.plus.com
Mon Feb 16 13:29:54 EST 2015


On 2015-02-16 17:07, David Aldrich wrote:
> Hi Peter
>
> Thanks very much for your reply. I have added one more question below.
>
>> The straightforward approach is to pass a list or tuple:
>>
>> def build(build_options=()):
>>     subprocess_check_call(("make",) + build_options)
>>
>> build(("flagA=true", "flagB=true"))
>
> This looks fine - I am trying it.
>
> I would like to display on the console the entire make command, so I have done this:
>
> def build(build_options=()):
>          make_command = 'make '.join(map(build_options))
>          print('Build command: ' + make_command)
>          subprocess.check_call(("make",)+build_options)
>
> but I get error:
>
> make_command = 'make '.join(map(build_options))
> TypeError: map() must have at least two arguments.
>
> What would be the correct way to concatenate and display the elements in the tuple please?
>
make_command = 'make ' + ' '.join(build_options)


You don't need 'map' because you're not doing anything to the options
before concatenating them.

The string before the .join is used as a separator between the joined
strings.




More information about the Python-list mailing list