Skip to content

Instantly share code, notes, and snippets.

@copyleftdev
Created February 13, 2020 05:51
Show Gist options
  • Save copyleftdev/9dec64bb38317f2c9d5de9158439a221 to your computer and use it in GitHub Desktop.
Save copyleftdev/9dec64bb38317f2c9d5de9158439a221 to your computer and use it in GitHub Desktop.
file search
def search_file(term, fname):
with open(fname, "r") as filein:
content = filein.read()
if term in content:
return True
else:
return False
def term_check():
term = input("Enter your search term: ")
fname = input("Enter your filename: ")
if search_file(term=term, fname=fname) is True:
print("the term '{}' was found in file {}".format(term, fname))
else:
print("The term '{}' was not found in file {}".format(term, fname))
term_check()
again = input('would you like to try again (y/n)')
if 'y' in again:
term_check()
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment