Python as a scripting language. Alternative to bash script?
Thomas Jollans
thomas at jollans.com
Mon Jun 28 12:26:33 EDT 2010
On 06/28/2010 06:08 PM, Dave Pawson wrote:
> Thanks for the replies (and Benjamin).
> Not met with the subprocess idea.
>
> On 28 June 2010 16:29, D'Arcy J.M. Cain <darcy at druid.net> wrote:
>
>>> Main queries are:
>>> Ease of calling out to bash to use something like imageMagick or Java?
>>
>> You don't need to call bash to call an external program. Check out the
>> subprocess module.
>
> Will do.
>
> If you do need a shell to simplify calling a
>> program (environment and wild card expansione.g.) don't call bash.
>
> I can get what I want from Python. No envars needed.
>
>
>
>>> Ease of grabbing return parameters? E.g. convert can return both
>>> height and width of an image. Can this be returned to the Python program?
>>
>> Just to set the terminology straight, a parameter is what you call the
>> function with. The return value is what it returns. The program
>> output is what it emits (prints.)
>
> My bad. I mean return values, though I do want
> program out from (for example) identify
If you're working with images, have a look at the PIL (Python Imaging
Library).
>
>
>>
>> Programs return an integer value. This is also called the exit
>> status.
>
> Sheer greed, for identify I may get either a return value or an exit
> status (bad input etc) :-)
> Looks like subprocess can hack it though.
>
>>
>> What you want is the output of the program. For this you need to
>> capture the output and parse it.
>>
>> Look at the subprocess module.
>
> Will do.
> tks D'Arcy (and Benjamin)
>
>
>
>
>
More information about the Python-list
mailing list