Multi-line strings with formatting

Steven Bethard steven.bethard at gmail.com
Sat Mar 24 03:07:33 EDT 2007


On Fri, 2007-03-23 at 09:54 -0700, gburde... at gmail.com wrote:
 > When constructing a particularly long and complicated command to be
 > sent to the shell, I usually do something like this, to make the
 > command as easy as possible to follow:
 > commands.getoutput(
 >     'mycommand -S %d -T %d ' % (s_switch, t_switch)   +
 >     '-f1 %s -f2 %s '         % (filename1, filename2) +
 >     '> %s'                   % (log_filename)
 >     )
 > Can anyone suggest a better way to construct the command, especially
 > without the "+" sign at the end of each line (except the last) ?

Paul McGuire wrote:
> This list might be even simpler to follow:
> 
> l = [
>      'mycommand',
>      '-S', s_switch,
>      '-T', t_switch,
>      '-f1', filename1,
>      '-f2', filename2,
>      '>', log_filename
>     ]
> cmd = " ".join(l)

And if you use the subprocess module, you won't even need (or want) the 
final join.

STeVe



More information about the Python-list mailing list