May-22-2018, 08:25 PM
sys.argv
is a way to get command line arguments into python.ex13.py 1 2 3
should do it.Test:
λ python foo.py 1 2 3 The script is called: foo.py The first variable is: 1 The second variable is: 2 The third variable is: 3Or string:
λ python foo.py hello world car The script is called: foo.py The first variable is: hello The second variable is: world The third variable is: car
sys.argv
is the simplest version of this,argparse is in standard library.There also many 3-part librarians for this Click(my favorite),Dotcop,Fire ect...