I accidentally used 'argparse' like this in my Python 3.9 program:
parser.add_argument ("-c, --clean", dest="clean", action="store_true")
parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true")
instead of:
parser.add_argument ("-c", "--clean", dest="clean", action="store_true")
parser.add_argument ("-n", "--dryrun", dest="dryrun", action="store_true")
So any use of 'my-prog.py -cn' threw an error:
error: unrecognized arguments: -cn
So is there something that throws an error on this wrong use of
"-c, --clean" instead? Could be useful. Or is "-c, --clean" legit somehow?
Are you trying to troll here?
get an error with this construction?
Thomas Passin wrote:
Are you trying to troll here?
You just showed how you got an error with this construction, so why are you asking how to
get an error with this construction?
I meant (obviously), another error-message besides:
error: unrecognized arguments: -cn
Perhaps from 'parser.add_argument ("-c, --clean", dest="clean", action="store_true")'
error: "-c, --clean", 2 options are unsupported.
BTW, accusing someone of 'trolling' is rather rude IMHO.
And thanks to ChrisA for a nice and normal answer.
nargs=0, const=True, default=False, type=None, choices=None,import argparse
parser = argparse.ArgumentParser()
parser.add_argument ("-c, --clean", dest="clean", action="store_true") _StoreTrueAction(option_strings=['-c, --clean'], dest='clean',
nargs=0, const=True, default=False, type=None, choices=None,parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true") _StoreTrueAction(option_strings=['-n, --dryrun'], dest='dryrun',
Namespace(clean=True, dryrun=False)parser.parse_args(["-c, --clean"])
On 3/18/2023 2:02 PM, Gisle Vanem via Python-list wrote:
I accidentally used 'argparse' like this in my Python 3.9 program:
parser.add_argument ("-c, --clean", dest="clean", action="store_true")
parser.add_argument ("-n, --dryrun", dest="dryrun", action="store_true")
instead of:
parser.add_argument ("-c", "--clean", dest="clean", action="store_true")
parser.add_argument ("-n", "--dryrun", dest="dryrun", action="store_true")
So any use of 'my-prog.py -cn' threw an error:
error: unrecognized arguments: -cn
So is there something that throws an error on this wrong use of
"-c, --clean" instead? Could be useful. Or is "-c, --clean" legit somehow?
Are you trying to troll here? You just showed how you got an error with
this construction, so why are you asking how to get an error with this construction?
On Sun, 19 Mar 2023 at 06:35, Gisle Vanem via Python-list <python-list@python.org> wrote:
Thomas Passin wrote:
Are you trying to troll here?You just showed how you got an error with this construction, so why are you asking how to
get an error with this construction?
I meant (obviously), another error-message besides:
error: unrecognized arguments: -cn
Perhaps from 'parser.add_argument ("-c, --clean", dest="clean", action="store_true")'
error: "-c, --clean", 2 options are unsupported.
BTW, accusing someone of 'trolling' is rather rude IMHO.
And thanks to ChrisA for a nice and normal answer.
I suspect the reason you were accused of trolling was that it was
quite unobvious what the difference was. When you ask for help with
something where the distinction is subtle (and you generally know it
was subtle by how long it took you to spot it!), it's often valuable
to pinpoint the exact issue, so people don't gloss over it and think
you posted the same code twice.
So please, try to think out how your questions will seem to the reader, and be clear about what you are asking. You may
not know the terminology that some other people use, but don't let that stop you from being clear about what you really
need to find out. Including more context is likely to be helpful, too. Don't leave it to the readers to infer what you
were thinking of.
Thomas Passin wrote:
So please, try to think out how your questions will seem to the
reader, and be clear about what you are asking. You may not know the
terminology that some other people use, but don't let that stop you
from being clear about what you really need to find out. Including
more context is likely to be helpful, too. Don't leave it to the
readers to infer what you were thinking of.
I'll do that. My post was written in a bit of a hurry
and frustration after struggling with my 'typo' for
30 minutes.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 16:52:02 |
Calls: | 10,389 |
Files: | 14,061 |
Messages: | 6,416,944 |