Skip to content

Instantly share code, notes, and snippets.

@cecepm
Created January 2, 2014 10:20
Show Gist options
  • Select an option

  • Save cecepm/8217319 to your computer and use it in GitHub Desktop.

Select an option

Save cecepm/8217319 to your computer and use it in GitHub Desktop.
argparse simple case, required input file, but optional output file
#!/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