parsing argument in python
问题 I have a problem I am trying to find a solution. I am not sure if I can do it with argparse. I want to be able to specify an option myprog -a 1 myprog -a 2 Now when I have a = 1 , I want to be able to specify b and c . But when a = 2 , I can only specify d . myprog -a 1 -b 3 -c 0 myprog -a 2 -d 3 Also a must always be specified 回答1: You can't do this with switched values as a single parse_args call, but you can do one of: Use sub-commands/sub-parsers Do partial parsing before fully