argparse list

Michele Simionato michele.simionato at gmail.com
Thu Sep 2 16:11:27 CEST 2010


On Sep 2, 1:45 pm, Neal Becker <ndbeck... at gmail.com> wrote:
> I'm interested in using argparse to parse a string formatted as:
>
> my_prog --option1=1,10,37
>
> That is, a list of comma delimited values.  I guess nargs almost does it,
> but expects options to be space-delimited.
>
> What would be the easiest approach?

In plac (http://pypi.python.org/pypi/plac) you would write the
following:

import plac

@plac.annotations(
    option1=('option with comma separated values',
             'option',
             'o',
             lambda x: x.split(',')))
def main(option1):
    print option1

if __name__ == '__main__':
    plac.call(main)



More information about the Python-list mailing list