![]() |
argparse --help in one line. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: argparse --help in one line. (/thread-29798.html) |
argparse --help in one line. - Denial - Sep-20-2020 Hello Following is the part of my code: help_msg = 'Encode video file(s) recursively to HEVC 10Bit.' parser = argparse.ArgumentParser(description=help_msg) parser.add_argument('-l', '--list', nargs='?', const=PWD, metavar='PATH', help='List all video files.') parser.add_argument('-c', '--hevc', nargs='?', const=PWD, metavar='PATH', help='List all HEVC video files.') parser.add_argument('-x', '--other', nargs='?', const=PWD, metavar='PATH', help='List all video files other than HEVC.') args = parser.parse_args()and this is the output: I want the 'optional arguments' part of help output be printed in the same line. Like this: How do I make it?Thanks RE: argparse --help in one line. - deanhystad - Sep-20-2020 import argparse import os PWD = os.getcwd() help_msg = 'Encode video file(s) recursively to HEVC 10Bit.' parser = argparse.ArgumentParser(description=help_msg, formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=30)) parser.add_argument('-l', '--list', nargs='?', const=PWD, metavar='PATH', help='List all video files.') parser.add_argument('-c', '--hevc', nargs='?', const=PWD, metavar='PATH', help='List all HEVC video files.') parser.add_argument('-x', '--other', nargs='?', const=PWD, metavar='PATH', help='List all video files other than HEVC.') args = parser.parse_args() parser.print_help()help(parser.formatter_class) You could also write your own HelpFormatter class.Personally I don't mind the extra lines and would prefer that all help use the same formatting. |