Message283713
| Author |
cykerway |
| Recipients |
cykerway |
| Date |
2016年12月21日.00:52:25 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1482281546.0.0.613026945443.issue29030@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|