I am trying to make my python script very user friendly, so I like to write some sort of help for it. What is your advise for this? 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?
You have to use Ctrl + I in front of an object's name to show their help in our Help pane.
Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics".
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With