[issue9653] New default argparse output to be added
Steven Bethard steven.beth...@gmail.com added the comment: I'm moving this over to Issue 11695, which proposes support for a usage/help message template. -- resolution: - duplicate stage: - committed/rejected status: open - closed superseder: - Improve argparse usage/help customization ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Steven Bethard steven.beth...@gmail.com added the comment: I see. When there are no arguments you basically want to replace the standard argparse help entirely with your own message, with your own capitalization, etc. What you're doing now looks like a pretty good approach for this, so I guess I'm still not clear what you're asking for. Could you suggest a concrete API for argparse that would make it easier to do what you want to do? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Tom Browder tom.brow...@gmail.com added the comment: ... I see. When there are no arguments you basically want to replace the standard argparse help entirely with your own message, with your own capitalization, etc. What you're doing now looks like a pretty good approach for this, so I guess I'm still not clear what you're asking for. Could you suggest a concrete API for argparse that would make it easier to do what you want to do? I think so, Steven, let me look at it a bit and I'll get back to you. Thanks, -Tom Thomas M. Browder, Jr. Niceville, Florida USA -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Tom Browder tom.brow...@gmail.com added the comment: On Sun, Aug 22, 2010 at 17:06, Steven Bethard rep...@bugs.python.org wrote: ... import argparse import sys parser = argparse.ArgumentParser() parser.add_argument('--foo') if len(sys.argv) == 1: parser.print_help() else: print(parser.parse_args()) Of course that works, but I want to be able to customize the parser so it shows something like: Usage: program name [options] Use option '-h' for help. Two problems for me with current behavior: 1. usage and optional = not capitalized 2. usage: temp.py [-h] [--foo FOO] = gets very lengthy and mind numbing for programs with lots of options Regards, -Tom -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Tom Browder tom.brow...@gmail.com added the comment: On Sun, Aug 22, 2010 at 16:01, Steven Bethard rep...@bugs.python.org wrote: Steven Bethard steven.beth...@gmail.com added the comment: A simpler approach might be to do this before your call to parse_args: if len(sys.argv[0]) == 1: parser.print_help() Does that solve your problem? No, Steven, I get no response at all. -Tom -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Steven Bethard steven.beth...@gmail.com added the comment: A simpler approach might be to do this before your call to parse_args: if len(sys.argv[0]) == 1: parser.print_help() Does that solve your problem? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Steven Bethard steven.beth...@gmail.com added the comment: Sorry, typo. Should have been len(sys.argv) == 1. Full script: import argparse import sys parser = argparse.ArgumentParser() parser.add_argument('--foo') if len(sys.argv) == 1: parser.print_help() else: print(parser.parse_args()) With that script, I see: $ ./python.exe temp.py usage: temp.py [-h] [--foo FOO] optional arguments: -h, --help show this help message and exit --foo FOO -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
New submission from Tom Browder tom.brow...@gmail.com: When I use the argparse module, and I enter my program name with NO arguments or options, I would like the argparser to output something like: Usage: program name [options] Use option '-h' for help. I haven't yet found how to do that in the argparse module source code, but I do that now in my programs by adding this code near the beginning of the program: # give rudimentary help if nothing but prog name is entered import os # get program name as it is called pnam = os.path.basename(sys.argv[0]) Use = Usage: {0} [options].format(pnam) if len(sys.argv) == 1: print(Use) print(Use option '-h' for help.) sys.exit() -- components: Library (Lib) messages: 114457 nosy: Tom.Browder priority: normal severity: normal status: open title: New default argparse output to be added type: feature request versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9653] New default argparse output to be added
Changes by Benjamin Peterson benja...@python.org: -- assignee: - bethard nosy: +bethard ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9653 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com