Python> Run-time argument> Check if -d is attached

Operating environment


Xeon E5-2620 v4 (8 cores) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 and its-devel
mpich.x86_64 3.1-5.el6 and its-devel
gcc version 4.4.7 (And gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Use 1.
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

When executing a Python script, check if -d is attached.

Reference: https://docs.python.jp/3/howto/argparse.html The part described in store_true.

test_python_170324a.py


import argparse

parser = argparse.ArgumentParser(description="do something")

parser.add_argument(
    '-d',
    '--debugMode',
    dest='debugMode',
    action='store_true',
    help='debug mode')

cmd_args = parser.parse_args()

if(cmd_args.debugMode == False):
	print("normal mode")
else:
	print("debug mode")

result


$ python test_python_170324a.py 
normal mode
$ python test_python_170324a.py -d
debug mode
$ python test_python_170324a.py --debugMode
debug mode

Recommended Posts

Python> Run-time argument> Check if -d is attached
Check if the string is a number in python
python> check NoneType or not> if a == None:> if a is None:
Check if the URL exists in Python
Check if the characters are similar in Python
Create Python folder Check if it already exists
(For myself) Flask_AWS_3 (Check if SQL is working)
Python if statement
Create a python script to check if the link at the specified URL is valid 2
Python nan check
Python is easy
python grammar check
Create a python script to check if the link at the specified URL is valid
What is python
How to check in Python if one of the elements of a list is in another list
[Python] if statement
Python is instance
python> Check if code is printable> Use ord () / all (c in string.printable for c in hello)
What is Python
Check if it is Unix in the scripting language
Check if the LAN cable is disconnected on Linux
Check if it is Unix in the scripting language
Why is the first argument of [Python] Class self?