Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Forked from nhoffman/pyscript.py
Last active January 3, 2022 20:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save n8henrie/d32362c971627ea3b5e6 to your computer and use it in GitHub Desktop.
Save n8henrie/d32362c971627ea3b5e6 to your computer and use it in GitHub Desktop.
Python script template
#!/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
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