1

I'm making a program you need to supply arguments to.

I want to use argparse but I can't figure out how I can make it work when I supply --full argument it should print full info about let's say airport containing code, name and city of airport, when --name and --code is supplied it would print just name and code of airport.

The question is how can I make --full and group of (--name, --code, --city) mutually exclusive?

I want something like this:

$./airports.py --full

{'city': 'London','name': 'Heathrow', 'code': 'LHR'}
...

$./airports.py --city --code

{'city': 'London', 'code': 'LHR'}
...



$./airports.py --city --code --full

Error: '--city' and '--code' can't be used with '--full'
cha0site
  • 10,517
  • 3
  • 33
  • 51
  • The duplicate isn't quite a duplicate. This question doesn't involve a positional. But my answer about doing your own testing after parsing is relevant. Anyways, the mutually-exclusive mechanism does not implement complex logic like this (no `any` or `and` logic - just a simple flat `xor`). – hpaulj Nov 25 '18 at 17:38
  • When you ask an `argparse` question, it is best if you provide the `parser` code that you have tried so far, and explain why it doesn't work as you want. This case is simple enough that we can guess what you have tried, or at least should have tried. – hpaulj Nov 25 '18 at 17:39

0 Answers0