Skip to content

Instantly share code, notes, and snippets.

@umeshG34
Forked from nhoffman/pyscript.py
Last active October 29, 2019 01:02
Show Gist options
  • Select an option

  • Save umeshG34/97c6c45649325bea84f9c53dcad61058 to your computer and use it in GitHub Desktop.

Select an option

Save umeshG34/97c6c45649325bea84f9c53dcad61058 to your computer and use it in GitHub Desktop.
Python script template
#!/usr/bin/env python
"""A simple python script template.
"""
from __future__ import print_function
import os
import sys
import argparse
def main(arguments):
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('infile', help="Input file", type=argparse.FileType('r'))
parser.add_argument('-o', '--outfile', help="Output file",
default=sys.stdout, type=argparse.FileType('w'))
args = parser.parse_args(arguments)
print(args)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
"""
Reference:
https://www.davidfischer.name/2017/01/python-command-line-apps/
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment