file="test.txt" #can be changed to your file path
total_file_lines=0 #file lines
debug=False #prints more info about what is happening if true
if ".txt" not in file: #add a .txt if the user forgot to add it
file+=".txt"
def Main(): #only runs if the file is not being imported and is the main program running (sets the number of lines in the file)
global total_file_lines
with open(file,"r") as f:
for line in f:
total_file_lines+=1
def SearchFile(terms): #searches the file for all the terms present in the "terms" array
i=0
with open(file,"r") as f:
for line in f:
i+=1
for term in terms:
if term in line:
if debug:
print("Term:"+term+" | Ln:"+str(i)+" | Entire Line:"+line)
return True
def SearchLine(lines,terms): #same thing as searchFile but only checks the lines within the lines array
i=0
with open(file,"r") as f:
for line in f: #loop through all the lines of the file
i+=1
if str(i) in str(lines): #if it is a line we want to check for coninue
for term in terms: #loop through all our terms
if term in line: #check if the term we are on is in the line we are on
if debug: #if we are debbuging print our rsults
print("Term:"+term+" | Ln:"+str(i)+" | Entire Line:"+line)
return True
def GetLine(spliting,lines): #just prints out the specified line as a list split by what ever the user wants for example (spliting this by spaces would look like this) = ["splitting","this","by","spaces","would","look","like","this"]
i=0
with open(file,"r") as f:
for line in f: #loop through all the lines of the file
i+=1
if str(i) in str(lines): #if it is a line we want to check for coninue
if debug: #if we are debbuging print our rsults
print("Ln:"+str(i)+" | Entire Line:"+line)
if spliting!="entire":
return line.split(spliting)
else:
return line
if __name__=="__main__": #calls main if it is the main programm running and not an imported module
Main()