Created
February 13, 2020 05:51
-
-
Save copyleftdev/9dec64bb38317f2c9d5de9158439a221 to your computer and use it in GitHub Desktop.
file search
This file contains 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
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