Skip to content

Instantly share code, notes, and snippets.

@gezerk
Created September 21, 2019 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gezerk/4e3efe53e2a461b2e36392a8c4f7e43c to your computer and use it in GitHub Desktop.
Save gezerk/4e3efe53e2a461b2e36392a8c4f7e43c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""pyscript.py
A simple python script template.
http://ajminich.com/2013/08/01/10-things-i-wish-every-python-script-did/
"""
import argparse
import sys
if sys.version_info[0] < 3:
raise Exception("Python 3 or a more recent version is required.")
def main(qux, foo=1, bar=2):
"""Main script where stuff happens."""
print("Foo: {}\nBar: {}\nQux: {}".format(foo, bar, qux))
def _cli():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
argument_default=argparse.SUPPRESS)
parser.add_argument('-f', '--foo', help="This is the foo argument")
parser.add_argument('-b', '--bar', help="This is the bar argument")
qux_help = ("This argument will show its default in the help due to "
"ArgumentDefaultsHelpFormatter")
parser.add_argument('-q', '--qux', default=3, help=qux_help)
args = parser.parse_args()
return vars(args)
if __name__ == '__main__':
main(**_cli())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment