Created
February 8, 2019 15:43
-
-
Save gmolveau/eade2f14371c0101f589f54f20c44c5e to your computer and use it in GitHub Desktop.
Python argparse example of a global variable usage
This file contains 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
import argparse | |
CONSOLE_ARGUMENTS = None | |
def test(): | |
print(CONSOLE_ARGUMENTS.color_enabled) | |
def main(): | |
parser = argparse.ArgumentParser(description='test script with global argparse') | |
parser.add_argument('-c', '--color', dest="color_enabled", action="store_true", help="color flag") | |
args = parser.parse_args() | |
global CONSOLE_ARGUMENTS | |
CONSOLE_ARGUMENTS = args | |
test() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment