If you have Python 2.7+, you can use argparse instead of optparse.
import argparse parser = argparse.ArgumentParser(description='Process benchmarks.') parser.add_argument("-b", "--benchmark", default=[], type=str, nargs='+', help="The benchmark to be loaded.") args = parser.parse_args() print args.benchmark
Script run example -
$ python sample.py -h usage: sample.py [-h] [-b BENCHMARK [BENCHMARK ...]] Process benchmarks. optional arguments: -h, --help show this help message and exit -b BENCHMARK [BENCHMARK ...], --benchmark BENCHMARK [BENCHMARK ...] The benchmark to be loaded. $ python sample.py -b bench1 bench2 bench3 ['bench1', 'bench2', 'bench3']
source share