Command line argument processing (Python docopt)

Hello I tried Python's docopt (command line argument processing) [^ 1].

In the example below, I tried the difference in the description of --oo, `--pp```, and` `--qq```. In the case of `--qq```, the result is returned as a list (this description may not be officially recommended).

$ ./docopt_test.py
{'--help': False,
 '--oo': None,
 '--pp': None,
 '--qq': [],
 'X': []}
$
$ ./docopt_test.py -o 0 -p 1 -q 2 3 4
{'--help': False,
 '--oo': '0',
 '--pp': '1',
 '--qq': ['2'],
 'X': ['3', '4']}
$

docopt_test.py


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def argsdocopt(doc):
    import docopt, textwrap
    return docopt.docopt(textwrap.dedent(doc))    

def main():
    """
    {f}: Test a docopt library.

    usage: {f} [-h] [-o O] [-p <P>|--pp <P>] [-q|--qq <Q>] [X...]
    
    options:
        -h, --help        show this help message and exit
        -o, --oo O        parameter O
        -p <P>, --pp <P>  parameter P
        -q, --qq <Q>      parameter Q
    """
    args = argsdocopt(main.__doc__.format(f=__file__))
    print(args)

if __name__ == '__main__':
    main()

[^ 1]: I also referred to "Python docopt usage memo".

Recommended Posts

Command line argument processing (Python docopt)
Specify a subcommand as a command line argument in Python
How to get a string from a command line argument in python
Decompose command arguments in one line in Python
python image processing
Python file processing
LINE heroku python
Template for creating command line applications in Python
[Python] How to test command line parser click
How to receive command line arguments in Python
My thoughts on python2.6 command line app template
[Introduction to Udemy Python3 + Application] 67. Command line arguments
Python distributed processing Spartan
Python default argument trap
python2 series / 3 series, character code and print statement / command line
File processing in Python
Command line introductory notes
Python: Natural language processing
Communication processing by Python
Multithreaded processing in python
Python default argument behavior
First Python image processing
Execute command from Python
Python function argument summary
Text processing in Python
Queue processing in Python
Image processing with Python
Basic Python command memo
nl command processing performance
Linux command line shortcut
Execute command from python
Python string processing illustration
Python command line analysis library comparison (argparse, click, fire)
Various processing of Python
Allow brew install of command line tools made in Python
Use Python 3 introduced with command line tools on macOS Catalina
"Let Python do the boring things" exercise ~ Command line mailer ~
[Python] Read command line arguments from file name or stdin
Asynchronous processing using LINE BOT: RQ (Redis Queue) in Python
Image processing with Python (Part 2)
100 Language Processing with Python Knock 2015
UTF8 text processing in python
python3 Measure the processing speed.
"Apple processing" with OpenCV3 + Python3
Fizzbuzz in Python (in one line)
[Python] Execute unix command (subprocess)
Twitter post from command line
Acoustic signal processing with Python (2)
[Line / Python] Beacon implementation memo
python> print> N line breaks> print ('\ n'* 3)> 4 line breaks> print ('\ n'* 3),> 3 line breaks
Execute external command in python
Acoustic signal processing with Python
Asynchronous processing (threading) in python
100 Language Processing Knock Chapter 1 (Python)
100 Language Processing Knock Chapter 2 (Python)
Try LINE Notify in Python
Image processing with Python (Part 1)
Run unix command on python
Image processing with Python (Part 3)
Image processing by python (Pillow)
Post processing of python (NG)