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, 2019 in Python by ana1504.k
• 7,910 points
1,800 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, 2019 by SDeb
• 13,300 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, 2019 in Python by Nymeria
• 3,560 points
4,566 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, 2019 in Python by Neel
• 3,020 points
2,419 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
3,084 views
+1 vote
7 answers
0 votes
2 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,060 views
0 votes
1 answer
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, 2019 in Python by SDeb
• 13,300 points
434 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,300 points
1,431 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP