Question

I would like to use argparse to take some (3) integer arguments, and use these as variables in the program body. Running the code below, each variable gets stored in a one element list. This is no big problem of course, but is it possible to set up the parser to put each value into a simple integer variable?

import argparse

def main():
    parser = argparse.ArgumentParser(description='three positional integer arguments.')
    parser.add_argument('picks', type=int, nargs='+', default=10,
                       help='number of selections per execution')
    parser.add_argument('minchunk', type=int, nargs='+', default=2,
                       help='min chunk size')
    parser.add_argument('maxchunk', type=int, nargs='+', default=8,
                       help='max chunk size')

    args = parser.parse_args(['1', '2', '3'])
    print args
    return 0

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top