How to use the optparse module

I found a module that wrote a python script and cleaned up how to pass options. That is optparse

The usage is as follows.

#First import the module
import optparse

#Creating the main object for the parser
parser = optparse.OptionParser()

#Add settings for each option
#In this case--Get it later if you give a debug argument
#The debug property of the options object becomes True
#help is--Displayed with each option when help is given
#usage A message.
parser.add_option("--debug",
	action="store_true",
	dest="debug",
	help="Debug option")

#options has the value of each option as an associative array.
#After that, it will be boiled or baked.
(options, args) = parser.parse_args()

It's very convenient because you don't have to worry about the order.

Recommended Posts

How to use the optparse module
How to use the ConfigParser module
How to use OptParse
How to use the generator
How to use the decorator
How to use the zip function
How to use the Raspberry Pi relay module Python
How to use Python's logging module
How to use argparse and the difference between optparse
[Linux] How to use the echo command
How to use the Linux grep command
How to use the IPython debugger (ipdb)
How to use TouchDesigner Python's external module
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
How to use the C library in Python
How to use MkDocs for the first time
How to use the graph drawing library Bokeh
How to use the Google Cloud Translation API
How to use the NHK program guide API
[Algorithm x Python] How to use the list
How to use Qt Designer
How to use search sorted
[gensim] How to use Doc2Vec
python3: How to use bottle (2)
Understand how to use django-filter
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to use Python argparse
How to use IPython Notebook
How to use Pandas Rolling