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