0

I am trying to print all the below content of text file once a keyword is encountered using python.

Below is the code which I have written.

Filepath="D:/xyz.txt"
with open(filepath)as fp
 for line in fp:
  for path in line.split(" ")
        if "error" or "exception "  in fp:#It #should print all the content after error or #exception in line
           print line 
  • Python keywords should be all lowercase, `with`, `for`, `print`, etc. – cdarke Mar 14 '18 at 08:26
  • You forgot to ask a question so I've made a guess as to what the problem is, assuming the glaring syntax errors are just a copy-paste issue. If that's not the problem, give an actual [mcve]. And please make more effort with the formatting next time. – jonrsharpe Mar 14 '18 at 08:28
  • I will keep next time in mind – user8981703 Mar 14 '18 at 08:32

0 Answers0