Writing a help for python script

Use argparse.

For example, with test.py:

import argparse

parser=argparse.ArgumentParser(
    description='''My Description. And what a lovely description it is. ''',
    epilog="""All is well that ends well.""")
parser.add_argument('--foo', type=int, default=42, help='FOO!')
parser.add_argument('bar', nargs="*", default=[1, 2, 3], help='BAR!')
args=parser.parse_args()

Running

% test.py -h

yields

usage: test.py [-h] [--foo FOO] [bar [bar ...]]

My Description. And what a lovely description it is.
    
positional arguments:
  bar         BAR!
    
optional arguments:
  -h, --help  show this help message and exit
  --foo FOO   FOO!
    
All is well that ends well.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)