Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Created October 3, 2012 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chadwhitacre/3830608 to your computer and use it in GitHub Desktop.
Save chadwhitacre/3830608 to your computer and use it in GitHub Desktop.
Script for Saxifrage Class to Chew On
#!/usr/bin/env python
# The "import" statement finds modules (whatever those are!) and defines names
# in a namespace (whatever that is!):
#
# http://docs.python.org/reference/simple_stmts.html#the-import-statement
#
# The "sys" module provides things related (apparently) to the interpreter
# (whatever that is!):
#
# http://docs.python.org/library/sys.html
import sys
USAGE = "Usage: ./find.py word filename [filename]*"
def fail(msg):
print >> sys.stderr, USAGE
print >> sys.stderr, msg
sys.exit()
try:
word = sys.argv[1]
except:
fail("Please provide a word to find.")
filenames = sys.argv[2:]
if not filenames:
fail("Please enter at least one filename.")
for filename in filenames:
try:
file_pointer = open(filename)
except IOError:
print >> sys.stderr, "Could not open file:", filename
continue
for line in file_pointer:
if word in line:
print filename
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment