This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年06月13日 12:36 by icegood, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg220432 - (view) | Author: Serhiy Ivanov (icegood) | Date: 2014年06月13日 12:36 | |
have 1.py as:
import argparse
import sys
print (sys.argv)
parser = argparse.ArgumentParser(prog='demo')
parser.add_argument('--host -h', help='host for the server of %(prog)', nargs=1, required=True, metavar='<host>')
parser.add_argument('--port -p', help='port for the server of %(prog)', nargs=1, required=True, metavar='<port>')
parser.parse_args(sys.argv)
and run C:\Python34\python.exe 1.py -h 1.
Will obtain:
Traceback (most recent call last):
File "1.py", line 7, in <module>
parser.parse_args(sys.argv)
File "C:\Python34\lib\argparse.py", line 1717, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "C:\Python34\lib\argparse.py", line 1749, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "C:\Python34\lib\argparse.py", line 1955, in _parse_known_args
start_index = consume_optional(start_index)
File "C:\Python34\lib\argparse.py", line 1895, in consume_optional
take_action(action, args, option_string)
File "C:\Python34\lib\argparse.py", line 1823, in take_action
action(self, namespace, argument_values, option_string)
File "C:\Python34\lib\argparse.py", line 1016, in __call__
parser.print_help()
File "C:\Python34\lib\argparse.py", line 2348, in print_help
self._print_message(self.format_help(), file)
File "C:\Python34\lib\argparse.py", line 2332, in format_help
return formatter.format_help()
File "C:\Python34\lib\argparse.py", line 278, in format_help
help = self._root_section.format_help()
File "C:\Python34\lib\argparse.py", line 208, in format_help
func(*args)
File "C:\Python34\lib\argparse.py", line 208, in format_help
func(*args)
File "C:\Python34\lib\argparse.py", line 515, in _format_action
help_text = self._expand_help(action)
File "C:\Python34\lib\argparse.py", line 602, in _expand_help
return self._get_help_string(action) % params
ValueError: incomplete format
|
|||
| msg220437 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2014年06月13日 13:01 | |
You are missing an 's' after the parens. It should be: %(prog)s |
|||
| msg220457 - (view) | Author: paul j3 (paul.j3) * (Python triager) | Date: 2014年06月13日 15:45 | |
It's essentially the same issue as http://bugs.python.org/issue21666. An error in the 'help' parameter is not caught until 'print_help' is called (via 'parse_args'). A possible improvement is to test the 'help' string during 'add_argument'. Similar testing for 'nargs' and 'metavar' has been proposed. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:04 | admin | set | github: 65946 |
| 2014年06月13日 15:45:27 | paul.j3 | set | nosy:
+ paul.j3 messages: + msg220457 |
| 2014年06月13日 13:01:45 | r.david.murray | set | status: open -> closed type: behavior nosy: + r.david.murray messages: + msg220437 resolution: not a bug stage: resolved |
| 2014年06月13日 12:36:17 | icegood | create | |