Message283713
Using `choices` option in `argparse` module caused unwanted behavior.
# Without `choices`
parser = argparse.ArgumentParser()
parser.add_argument('length')
parser.print_help()
## Output
usage: demo.py [-h] length
positional arguments:
length
optional arguments:
-h, --help show this help message and exit
# With choices
parser = argparse.ArgumentParser()
parser.add_argument('length', choices=[1,2,3])
parser.print_help()
## Output
usage: demo.py [-h] {1,2,3}
positional arguments:
{1,2,3}
optional arguments:
-h, --help show this help message and exit
I think the doc says ArgumentParser objects use the `dest` value as the “name” of each object. And the doc doesn't mention anything about `dest` be changed by `choices`. The help text looks ugly when there is a long list of choices.
Currently the problem can be remedied by adding a `metavar` option. But I hope it will be fixed in the library itself. |
|
Date |
User |
Action |
Args |
2016-12-21 00:52:26 | cykerway | set | recipients:
+ cykerway |
2016-12-21 00:52:26 | cykerway | set | messageid: <1482281546.0.0.613026945443.issue29030@psf.upfronthosting.co.za> |
2016-12-21 00:52:25 | cykerway | link | issue29030 messages |
2016-12-21 00:52:25 | cykerway | create | |
|