argparse csv + choices

Neal Becker ndbecker2 at gmail.com
Wed Mar 30 11:32:48 EDT 2011


I'm trying to combine 'choices' with a comma-seperated list of options, so I 
could do e.g., 

--cheat=a,b

    parser.add_argument ('--cheat', choices=('a','b','c'), type=lambda x: 
x.split(','), default=[])

test.py --cheat a
 error: argument --cheat: invalid choice: ['a'] (choose from 'a', 'b', 'c')

The validation of choice is failing, because parse returns a list, not an item.  
Suggestions?




More information about the Python-list mailing list