[Tutor] Argparse and how best to use it :p:

Paradox paradox at pobox.com
Thu Oct 24 20:23:50 CEST 2013


On 10/24/2013 12:50 PM, Dave Angel wrote:
>>
>> Not sure which tutorial you're using, but the refernce page:
>>     http://docs.python.org/3.3/library/argparse.html
Actually I am using 2.7.5, the tutorial found here: 
http://docs.python.org/2/howto/argparse.html#id1

but the problem is the same.
>> import argparse
>>
>> def parse_my_args():
>>       global args
>>       parser = argparse.ArgumentParser(description='Process some
>> integers.')
>>       parser.add_argument('integers', metavar='N', type=int,
>> nargs='+', help='an integer for the accumulator')
>>       parser.add_argument('--sum', dest='accumulate',
>> action='store_const', const=sum, default=max, help='sum the integers
>> (default: find the max)')
>>       args = parser.parse_args()
>>
>>
This is exactly what I needed to un-stick my thinking about this, thanks!

thomas


More information about the Tutor mailing list