Skip to content

Instantly share code, notes, and snippets.

@kccheung
Forked from n8henrie/pyscript.py
Created April 30, 2018 03:04
Show Gist options
  • Save kccheung/cc5c0dc729ea996cf48228463be14845 to your computer and use it in GitHub Desktop.
Save kccheung/cc5c0dc729ea996cf48228463be14845 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