class FooAction(argparse.Action):

    def __call__(self, parser, namespace, values, option_string=None):
        print('Setting: %r %r %r' % (namespace, values, option_string))
setattr(namespace, self.dest, 'action:' + values)
p = argparse.ArgumentParser()
a1 = p.add_argument('--foo', action=FooAction, default='default')
print('action:', a1)
print(p.parse_args([]))
ns = argparse.Namespace()
a1(p, ns, a1.default, 'no string')
print(p.parse_args([], ns))
print(p.parse_args(['--foo', '1'], ns))
Cause Python's argparse to execute action for default