0
#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
3
Contributors
3
Replies
25
Views
2 Years
Discussion Span
Last Post by megaflo
1

It seems to me that you only need to remove lines 14 and 18 from the above program to get a start.

Edited by Gribouillis

0

Give me some solution, of course I will. All you need do is write a sizeable cheque made payable to the Python Software Foundation. When it's been cashed I'll give you a solution. When I say sizeable I am of course referring to the numbers and words indicating ow much is to be paid, not the physical dimensions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.