Created
April 13, 2017 13:34
-
-
Save fawix/9bed924a07cea66750368c69bf798d69 to your computer and use it in GitHub Desktop.
Python - Verbose Flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-v', '--verbose', action='count', default=0) | |
for c in ['', '-v', '-v -v', '-vv', '-vv -v', '-v -v --verbose -vvvv']: | |
print parser.parse_args(c.split()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code snippet shows how to do verbose arguments with Python
argparse
. The way to use these is to put the count result in a variable and then use if statements in order to determine the verbosity and print messages accordingly.Something like: