-
-
Save n8henrie/d32362c971627ea3b5e6 to your computer and use it in GitHub Desktop.
Python script template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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