argparse list

Peter Otten __peter__ at web.de
Thu Sep 2 08:34:21 EDT 2010


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 'and None'?

To hide the result of p.add_argument().

>>> "irrelevant junk"
'irrelevant junk'
>>> "irrelevant junk" and None
>>>

I'm not going to do it again ;)

Peter



More information about the Python-list mailing list