Created
January 2, 2014 10:20
-
-
Save cecepm/8217319 to your computer and use it in GitHub Desktop.
argparse simple case, required input file, but optional output file
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 | |
| # encoding: utf-8 | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('infile', type=argparse.FileType('r'), help='Input file in CSV format.') | |
| parser.add_argument('-o', '--outfile', type=argparse.FileType('wb'), help='Output file in CSV format.') | |
| args = parser.parse_args() | |
| if args.outfile: | |
| print "save output to OUTFILE" | |
| else: | |
| print "print to screen" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment