Skip to content

Instantly share code, notes, and snippets.

@rbarzic
Created February 25, 2015 19:59
Show Gist options
  • Save rbarzic/1f3a74f2558676fb5683 to your computer and use it in GitHub Desktop.
Save rbarzic/1f3a74f2558676fb5683 to your computer and use it in GitHub Desktop.
Reading a file line by line in python (with argument)
#!/usr/bin/env python
import argparse
def get_args():
"""
Get command line arguments
"""
parser = argparse.ArgumentParser(description="""
Put description of application here
""")
parser.add_argument('--infile', action='store', dest='infile',
help='file to be read')
parser.add_argument('--version', action='version', version='%(prog)s 0.1')
return parser.parse_args()
if __name__ == '__main__':
args = get_args()
with open(args.infile) as f:
for line in f:
print ">" + line.strip('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment