here is a simple example.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-a', action = 'append_const', dest = 'letter', const = 'a')
parser.add_argument('-b', action = 'append_const', dest = 'letter', const = 'b')
parser.set_defaults(letter = ['a', 'b'])
print(parser.parse_args('-a'.split()))
print(parser.parse_args('-b'.split()))
print(parser.parse_args(''.split()))
Results :
Namespace(letter=['a', 'b', 'a'])
Namespace(letter=['a', 'b', 'b'])
Namespace(letter=['a', 'b'])
Without the set_defaults line, results are :
Namespace(letter=['a'])
Namespace(letter=['b'])
Namespace(letter=None)
How is it possible to configure argparse for such results ?
Namespace(letter=['a'])
Namespace(letter=['b'])
Namespace(letter=['a', 'b'])