Mandar Pande Mandar Pande - 2 months ago 19
Python Question

How to use getopt/OPTARG in Python? How to shift arguments if too many arguments (9) are given?

How to use getopt/optarg in Python?

Answer

This is an example of how I do it, I usually use the same basic template:

import sys
import getopt

try:
    opts, args = getopt.getopt(sys.argv[1:], 'm:p:h', ['miner=', 'params=', 'help'])
except getopt.GetoptError:
    usage()
    sys.exit(2)

for opt, arg in opts:
    if opt in ('-h', '--help'):
        usage()
        sys.exit(2)
    elif opt in ('-m', '--miner'):
        miner_name = arg
    elif opt in ('-p', '--params'):
        params = arg
    else:
        usage()
        sys.exit(2)

I don't think there is any 9 parameter limit.