Skip to content

Instantly share code, notes, and snippets.

@habbis
Forked from GuyAllard/skeleton.py
Created February 9, 2021 15:47
Show Gist options
  • Save habbis/bdceea6333d052c6cc8314a6ca445b38 to your computer and use it in GitHub Desktop.
Save habbis/bdceea6333d052c6cc8314a6ca445b38 to your computer and use it in GitHub Desktop.
A python script skeleton
#! /usr/bin/env python
"""
A skeleton python script which reads from an input file,
writes to an output file and parses command line arguments
"""
from __future__ import print_function
import sys
import argparse
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"input", nargs="?", default="-",
metavar="INPUT_FILE", type=argparse.FileType("r"),
help="path to the input file (read from stdin if omitted)")
parser.add_argument(
"output", nargs="?", default="-",
metavar="OUTPUT_FILE", type=argparse.FileType("w"),
help="path to the output file (write to stdout if omitted)")
args = parser.parse_args()
for line in args.input:
print(line.strip(), file=args.output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment