Find (Ctrl + F)
Just like the find function in webpages and text editors, this code takes a file, and a given string to find in that file. Once it has been found, it returns the line it was found in, and the line number of that line. If nothing is found, nothing is returned, and it also returns multiple results if there are multiple times where that string shows up.
def find():
fo = open(input("Enter the name of your file: "), "r+")
context = input("Enter the search paramaters: ")
lines = fo.readlines()
for x in range(0, len(lines)):
if context in lines[x]:
print("The given is in the file, within the line, ", lines[x])
print("In line number", x-1)
Comments
Post a Comment