Writing a help for python script

0 votes
I am trying to make my python script very user friendly, so I like to write some sort of help for it. I could just put in some logic that if the user passed help as a paramater to the script, they get help. Is there a best practise or convention for this?
Apr 25 in Python by ana1504.k
• 7,870 points
22 views

1 answer to this question.

0 votes
You can use argparse.

For example, with test.py:

import argparse

parser=argparse.ArgumentParser(
    description='''My Description. And what a lovely description it is. ''',
    epilog="""All's 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!
answered Apr 25 by SDeb
• 13,160 points

Related Questions In Python

0 votes
1 answer

Need help extracting a schema to make use for an avro file in Python

Hi, nice question. So what I daily use ...READ MORE

answered Jan 10 in Python by Nymeria
• 3,520 points
482 views
0 votes
1 answer

How to write a python script for downloading a video from YouTube and saving it to a directory?

First download pytube using the following code  pip ...READ MORE

answered Sep 4 in Python by Neel
• 3,010 points
402 views
0 votes
1 answer

Need help writing a dataframe into a csv with the help of a loop

Using the following logic you can arrive ...READ MORE

answered Apr 17, 2018 in Python by anonymous
943 views
+1 vote
3 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 233 views
0 votes
1 answer

Find out time it took for a python script to complete execution

You can try the following code and ...READ MORE

answered Aug 6 in Python by SDeb
• 13,160 points
11 views
+1 vote
1 answer

How to Profile a script in Python

Python includes a profiler called cProfile. It ...READ MORE

answered Nov 21, 2018 in Python by SDeb
• 13,160 points
63 views