Possible Duplicate:
Command Line Arguments In Python
Example:
itp.threads[0].memload(r"c:\FistForSOCAD_PASS.bin","0x108000P")
itp.threads[0].cv.cip = "0x108000"
itp.go()
itp.halt()
I would like to make above example as a python script and "FistForSOCAD_PASS.bin" can be replaced by an argument. Because it is only the variable thing.
Example command to run the script will be like:
python itp.py FistForSOCAD_PASS.bin
There are a number of ways, One is this approach:
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',
help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
const=sum, default=max,
help='sum the integers (default: find the max)')
args = parser.parse_args()
print args.accumulate(args.integers)
Which gives:
$ prog.py -h
usage: prog.py [-h] [--sum] N [N ...]
Process some integers.
positional arguments:
N an integer for the accumulator
optional arguments:
-h, --help show this help message and exit
--sum sum the integers (default: find the max)
Read more at docs.python.org
You may use sys.argv:
sys.argv
The list of command line arguments passed to a Python script.
argv[0]is the script name (it is operating system dependent whether this is a full pathname or not). [...]
Example:
import sys
if len(sys.argv) > 1:
filename = sys.argv[1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With