Skip to content

Instantly share code, notes, and snippets.

@cjerrington
Forked from n8henrie/pyscript.py
Created October 6, 2019 15:31
Show Gist options
  • Save cjerrington/0e5e207416d4d27d47eeec232fa39d51 to your computer and use it in GitHub Desktop.
Save cjerrington/0e5e207416d4d27d47eeec232fa39d51 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