python argparse template

python v2.7 has a module called argparse that makes it easy to set arguments. With this, you can easily create a python script, so I will post a template.


# coding:utf-8
import argparse

if __name__ == '__main__':
	parser = argparse.ArgumentParser(description='description')
	parser.add_argument('arg1', type=int, help='integer argument')
	parser.add_argument('arg2', type=str, help='string argument')
# -a or--True if all is specified,If not False is args.Stored in all
	parser.add_argument('-a', '--all', action='store_true') 
	parser.add_argument('--seeds', nargs=2, type=int, help='int options')
	args = parser.parse_args()
	your_method(args.arg1, args.arg2)

One of the useful things about argparse is

Besides, it is possible to handle many arguments and bundle the arguments in a list, but for the time being, a brief explanation.

Recommended Posts

python argparse template
[Python] Tkinter template
Competitive Pro Template (Python)
Python data analysis template
Jinja2 | Python template engine
python unit test template
Python template engine empy
Python
argparse
How to use Python argparse
Python template for Codeforces-manual test-
[Python] Competitive template [At Coder]
template
Python Design Pattern --Template method
Competitive programming, coding test template: Python3
Preprocessing template for data analysis (Python)
Template AtCoder ABC 179 Python (A ~ E)
kafka python
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
I compared python3 standard argparse and python-fire
Python comprehension
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python tips
Python memo
Python comprehension
Python Singleton
Python basics ④
Python Memorandum 2
argparse part 1
Python increment
atCoder 173 Python
[Python] function
Python installation
python tips
Installing Python 3.4.3.
Try python
Python memo
Python iterative
Python algorithm
Python2 + word2vec
[Python] Variables
Python functions
Python sys.intern ()
Python tutorial
Django # 2 (template)
Python decimals
python underscore
Python summary
Start python
argparse note
[Python] Sort
Note: Python
Template for writing batch scripts in python
Python basics ③