Using Python instead of Bash

Cameron Simpson cs at zip.com.au
Sun May 31 18:57:13 EDT 2015


On 31May2015 11:05, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>	I'll concede submitting jobs to a print queue probably does work easier
>this way, but I'd have to ask if the "convert" could be performed using
>actual Python -- the old Python Imaging Library -- PIL -- for example
>(superseded, I think, by pillow)?

(Yes, PIL is stale, Pillow is live.)

Or, more direct if Pillow doesn't have what he wants, is to use the ImageMagick 
or GraphicsMagick Python libraries. Anything ImageMagick can do via the command 
line they should be able to do directly.

The advantage of using PIL/Pillow or ImageMagick/GraphicsMagick within Python 
is that, memory permitting, one can avoid making (and therefore needing to 
clean up) temporary files.

>	Given that you do nothing between creating a subprocess and waiting for
>it to exit, subprocess.Popen() could be overkill -- the simpler
>subprocess.call() could be sufficient (heck, the old os.system() is
>sufficient, but preference seems to be to ignore it for subprocess.call()
>instead).

os.system passed a string to the shell. That has quoting/security issues.  
(Exactly like shell=True with subprocess.)

With his specific example this isn't a big deal because all the filenames are 
benign etc, but as a general rule using subprocess and passing explicit command 
line argument strings is safer.

All of which you know, I know. But good to get it said in the thread.

Cheers,
Cameron Simpson <cs at zip.com.au>



More information about the Python-list mailing list