jeudi 29 mars 2018

how to fix the display format of the return result in python

i have a function that read file and display the matching word using regular expression .

the system display the result like this :

if
Exist on Line 1
if
Exist on Line 2

what i want is to make the result look like this :

if exist 2 times
on line 1
on line 2

code:

def searchWord(self,selectedFile):
        fileToSearchInside = self.readFile(selectedFile)
        searchedSTR = self.lineEditSearch.text()

        textList = fileToSearchInside.split('\n')

        counter = 1
        for myLine in textList:
            theMatch = re.findall(searchedSTR,myLine,re.MULTILINE|re.IGNORECASE)

            if(len(theMatch) > 0 ):
                print(theMatch[0])
                print("Exist on Line {0}".format(counter))
                counter+=1        

Aucun commentaire:

Enregistrer un commentaire