argparse part 1

I tried using it for the time being

import argparse

parser = argparse.ArgumentParser(description="hoge")
args = parser.add_argument("-d","--dir",default="./")
args = parser.parse_args()

print args.dir

http://docs.python.jp/2.7/library/argparse.html#module-argparse The explanation was too sophisticated and I didn't know what it was, but it worked for the time being.

If you write "-d", "--dir" in add_argument, you can specify the option, and you can also specify the default value. So, parse_args will return the result taken from sys.argv like an object. I didn't know what the namespace object was, but it seems like this is the way to use it.

Recommended Posts

argparse part 1
argparse
datetime part 1
argparse note
numpy part 2
Queuing theory part 4
neo4j sandbox part 12
QGIS + Python Part 2
neo4j sandbox part 5
Django begins part 1
Manim's method part 23
Report_Deep Learning (Part 2)
Report_Deep Learning (Part 1)
Report_Deep Learning (Part 1)
QGIS + Python Part 1
GMT installation part 2.
GMT installation part 1.
Django begins part 4
Report_Deep Learning (Part 2)
neo4j sandbox part 13
neo4j sandbox part 15
Queuing theory part 3
python argparse template
Python: Scraping Part 1
neo4j sandbox part 16
neo4j sandbox part 11
Python3 Beginning Part 1
Python: Scraping Part 2
pandas series part 1