ให้ทำการเรียกใช้ argparse โดยใช้คำสั่ง
Code: Select all
import argparse
Code: Select all
import argparse
parser = argparse.ArgumentParser()
parser.parse_args()
Code: Select all
python <ชื่อไฟล์ python> -h
Code: Select all
python <ชื่อไฟล์ python> --help
Code: Select all
parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")
Code: Select all
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")
parser.add_argument("-v2", "--verbose2", help="increase output verbosity", action="store_true")
args = parser.parse_args()
if args.verbose == True:
print "verbosity turned on"
if args.verbose2 == True:
print "verbosity2 turned on"
อ้างอิง
https://docs.python.org/2/howto/argparse.html
http://keancode.github.io/python/argparse.html
https://python3.wannaphong.com/2015/04/python_15.html