return a value to shell script

News123 news123 at free.fr
Fri Nov 14 22:01:42 CET 2008


I don't know what exactly your python script is doing and what kind of
return value you have,

Let's assume your python application prints nothing to stdout, then
python could print out the return value and you could get it with the
back ticks (reverse single quote)
(at least for sh bash csh tcsh and probably also for ksh and some others)




Example
>>>>>>>>>> beginning of python script numtotext.py
import sys
a=['zero','one','two','three']
b = int(sys.argv[1])
###your python script can still print to stderr if it likes to
print >> sys.stderr, "I am no converting"
result = a[b]
print result
>>>>>>> end of python script


>>>>>beginning of shell script
#!/bin/sh

num=2
text=`python numtotext.py $num`
echo "$num as text is $text"
>>>>> end of shell script

bye


N


devi thapa wrote:
> Hi,
> 
> I am executing a python script in a shell script.  The python script
> actually returns a value.
> So, can I get the return value in a shell script? If yes, then help me out.
> 
> Regards,
> Devi



More information about the Python-list mailing list