Skip to content

Instantly share code, notes, and snippets.

@hoehermann
Created July 27, 2023 21:32
Show Gist options
  • Select an option

  • Save hoehermann/08d56f62a0b04e88697feba2f362884b to your computer and use it in GitHub Desktop.

Select an option

Save hoehermann/08d56f62a0b04e88697feba2f362884b to your computer and use it in GitHub Desktop.

Revisions

  1. hoehermann created this gist Jul 27, 2023.
    8 changes: 8 additions & 0 deletions condargparse.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--format', required=True, choices=['binary', 'xml', 'text'])
    args, rem_args = parser.parse_known_args()
    if (args.format == "text"):
    parser.add_argument('--encoding', required=True)
    parser.parse_args(rem_args, namespace=args)
    # this does not work since required argument has already been consumed