Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Created February 8, 2019 15:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmolveau/eade2f14371c0101f589f54f20c44c5e to your computer and use it in GitHub Desktop.
Save gmolveau/eade2f14371c0101f589f54f20c44c5e to your computer and use it in GitHub Desktop.
Python argparse example of a global variable usage
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