On Thu, Oct 10, 2019 at 2:37 PM brent bejot <brent.bejot@gmail.com> wrote:
On Wed, Oct 9, 2019 at 11:01 PM Ryan Gonzalez <rymg19@gmail.com> wrote:
I believe you want Python 3.7's parse_intermixed_args: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.pars...
A quick test seems to work:
import argparse
p = argparse.ArgumentParser() p.add_argument('files', nargs='*') p.add_argument('-f', '--force', action='store_true')
print(p.parse_intermixed_args())
$ python3 rm.py x -f y Namespace(files=['x', 'y'], force=True) $
This is EXACTLY what I've been looking for. Looks like it was added in 2017 and release in 3.7. The box I use where I investigated this has 3.6 on it. Sigh, well at least I know it was a good idea! Thanks so much!
Welp, I learned something new today too :) Thanks Ryan for pointing that out! What you may want to consider is backporting the exact argparse.py from Python 3.7. It's a fairly straight-forward module and will probably work fine on 3.6. That way, once you upgrade to 3.7, it'll keep working the exact same way. ChrisA