Executing a command from within python using the subprocess module

Alf P. Steinbach alfps at start.no
Mon Feb 15 13:44:32 CET 2010


* R (Chandra) Chandrasekhar:
> 
> width = 5
> height = 30
> colors = ['#abcdef]', '#456789']
> filename = "/tmp/image.png"
> 
> # I want to get the equivalent of variable interpolation in Perl
> # so that the command
> #
> # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png
> #
> # is derived from the variables above

Assuming that the extra right square bracket in 'colors' is a typo, here's one way:

     s = "convert -size {w}x{h} gradient:{g1}-{g2} {f}".format(
         w = width, h = height, g1 = colors[0], g2 = colors[1], f = filename
         )


Cheers & hth.,

- ALf



More information about the Python-list mailing list