Skip to content

Instantly share code, notes, and snippets.

@opie4624
Last active May 24, 2024 04:36
Show Gist options
  • Save opie4624/3896526 to your computer and use it in GitHub Desktop.
Save opie4624/3896526 to your computer and use it in GitHub Desktop.
Base Python Command Line template
#!/usr/bin/env python
#
# import modules used here -- sys is a very standard one
import sys, argparse, logging
# Gather our code in a main() function
def main(args, loglevel):
logging.basicConfig(format="%(levelname)s: %(message)s", level=loglevel)
# TODO Replace this with your actual code.
print "Hello there."
logging.info("You passed an argument.")
logging.debug("Your Argument: %s" % args.argument)
# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description = "Does a thing to some stuff.",
epilog = "As an alternative to the commandline, params can be placed in a file, one per line, and specified on the commandline like '%(prog)s @params.conf'.",
fromfile_prefix_chars = '@' )
# TODO Specify your real parameters here.
parser.add_argument(
"argument",
help = "pass ARG to the program",
metavar = "ARG")
parser.add_argument(
"-v",
"--verbose",
help="increase output verbosity",
action="store_true")
args = parser.parse_args()
# Setup logging
if args.verbose:
loglevel = logging.DEBUG
else:
loglevel = logging.INFO
main(args, loglevel)
@lparolari
Copy link

Thanks!

@a2nath
Copy link

a2nath commented Mar 14, 2022

Great, thanks for maintaining it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment