Bash Execute Python

Published: by Creative Commons Licence

Simple Example

$ foo="hello world"; python -c "print('$foo')"

$ bar=`python -c "print('hello world')"`; echo $bar

$ foo="hello world"
$ python << EOF
> print('$foo')
> EOF

Send Parameters to python

$ python -c "import sys; print(sys.argv[1])" "hello world"

Execute Python Script

$ python test.py "hello world"
# test.py
import sys
print(sys.argv[1])

Reference