argparse '--' not working?

N

Neal Becker

It is a 'standard' behaviour that a lone '--' terminates options. argparse
says:

If you have positional arguments that must begin with '-' and don’t look
like negative numbers, you can insert the pseudo-argument '--' which tells
parse_args that everything after that is a positional argument:

But it doesn't seem to work:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument ('--submit', '-s', action='store_true')
parser.add_argument ('--list', '-l', action='store_true')
opt = parser.parse_args()

../queue --submit -- test1.py -n
usage: queue [-h] [--submit] [--list]
queue: error: unrecognized arguments: -- test1.py -n
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top