#I'm begginer for python. I want a program which accept search phrase as raw_input and print search phrase with which document it exists in and line number of the document (file). for example, search phrase is found in file name at line 6. but my program displays 0 and 0 with continueos loop.
this is my code
# VARIABLE DEFINITIONS
searchPhrase = ""
line = ""
lineNumber = 0
jargonFile = ""
characterPos = 0
readLine = ""
#PROGRAM'S MAIN LOGIC
searchPhrase = raw_input("Enter search phrase: ")
while searchPhrase != "":
with open('doc1.txt','r') as myfile:
for line in myfile:
while line != "":
if searchPhrase in line:
characterPos = line.find(searchPhrase)
print "Search phrase found in line: ", lineNumber, " at", characterPos
lineNumber = lineNumber + 1
misgee2001 0 Newbie Poster
misgee2001 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
megaflo 29 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.