Re: argparse list

2010-09-02 Thread Michele Simionato
On Sep 2, 1:45 pm, Neal Becker 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?

Re: argparse list

2010-09-02 Thread Peter Otten
Neal Becker wrote: > Peter Otten wrote: > > import argparse > def csv(value): >> ... return map(int, value.split(",")) >> ... > p = argparse.ArgumentParser() > p.add_argument("--option1", type=csv) and None > p.parse_args(["--option1=1,10,37"]) > > Thanks! But, why the '

Re: argparse list

2010-09-02 Thread Neal Becker
Peter Otten wrote: import argparse def csv(value): > ... return map(int, value.split(",")) > ... p = argparse.ArgumentParser() p.add_argument("--option1", type=csv) and None p.parse_args(["--option1=1,10,37"]) Thanks! But, why the 'and None'? -- http://mail.python.

Re: argparse list

2010-09-02 Thread Peter Otten
Neal Becker 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? >>> import argp