[Tutor] Pass arguments from bash script to embedded python script
Mats Wichmann
mats at wichmann.us
Mon Oct 21 11:39:17 EDT 2019
On 10/21/19 7:45 AM, Stephen P. Molnar wrote:
> my problem is how do I pass the argument's in the two files from the
> bash script to the python script? It has been suggested to me that the
> solution is an implementation of the sys/.argv function but it seems
> that every reference that I can find goes the other way from python to
> bash.
perhaps this will illustrate:
[mats at boulder tmp]$ cat call.sh
python3 script.py A B C
[mats at boulder tmp]$ cat script.py
import sys
print("Called with:", sys.argv)
[mats at boulder tmp]$ sh call.sh
Called with: ['script.py', 'A', 'B', 'C']
usually you'll start your processing at sys.argv[1], since [0] is the
script name itself. That incantation often appears as:
args = sys.argv[1:]
More information about the Tutor
mailing list