1

CPython itself has certain command-line options that cause all further arguments to be interpreted as non-options ("terminates option list"). For example, -c cmd is such an option, so python3 -c 'import sys; print(sys.argv)' -E prints [-c, -E]; -E isn't recognized as an option.

Is there a way to define an option of this kind for an argparse parser?

Kodiologist
  • 2,984
  • 18
  • 33
  • The double dash '--' can be used this way. `nargs=argparser.REMAINDER` also. Look up them up in the argparse docs. – hpaulj Jun 13 '20 at 20:29
  • @hpaulj I'm familiar with both, but I don't see how to use either to solve this exact problem. – Kodiologist Jun 14 '20 at 00:03
  • 1
    In `argparse` an Action can only process the 'nargs' strings that it's given. The only alternative is to raise an error, or system exit (as done by a help-action). In `optparse` the options do get the rest of `sys.argv` and can do what they want with it. Not so in `argparse`. – hpaulj Jun 14 '20 at 06:58

0 Answers0