mercredi 7 mars 2018

How to find more words in a file at once?

In my program I am reading another python program and I want to find some special python keywords. When I find them I want to print out some code in front of that keyword found and after it.

This is my code:

if line.find("def") == True or line.find("if") == True or line.find("elif") == True:
   print("<span style=\"color: orange;\">",True,"</span>","<br>", end="") 

In the print statement "True" I want it to be the value that was read by the program.

I don't know if I am doing the "or" statement right but the output is not working. I don't get any error or anything . I expect my output to be the HTML code above and then the keyword found and the closing HTML code.

Example Output:

<span style=\"color: orange;\">if</span>
<span style=\"color: orange;\">def</span> 
<span style=\"color: orange;\">elif</span>

Aucun commentaire:

Enregistrer un commentaire