I already construct one custom action of argparse in python. However, when I add more custom actions, it seems not working.
class first_action(argparse.Action):
def __call__(self, parser, args, values, option_string=None):
print("the 1st")
if ...:
raise IndexError(...)
elif ...:
raise IndexError(...)
else:
setattr(args, self.dest, values)
This is the first custom action I made, and it worked
If I added more,
class second_action(argparse.Action):
def __call__(self, parser, args, value, option_string=None):
print("the 2nd")
if ...:
setattr(args, self.dest, fn1(value))
else:
setattr(args, self.dest, value)
class third_action(argparse.Action):
def __call__(self, parser, args, value, option_string=None):
print("the 3rd")
if ...:
setattr(args, self.dest, fn2(value))
else:
setattr(args, self.dest, value)
It worked but just passed the 2nd and 3rd actions and showed the message "the 1st" Here, only the 1st custom action is working.
parser.add_argument('-f', action=first_action) <-- action working
parser.add_argument('-s', action=second_action) <-- action not working
parser.add_argument('-t', action=third_action) <-- action not working