Created
March 16, 2016 10:51
-
-
Save GuyAllard/b386406652107ad2972d to your computer and use it in GitHub Desktop.
A python script skeleton
This file contains hidden or 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 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