Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

set row number to document and get data in pyton

I have a series of files and I have to separate and display part of the text

my code is :

path = 'C:\\Bot\\*.log' 
files = glob.glob(path) 
nlines = 0
for name in files: 
    try: 
        with open(name) as f:
            for line in f :
                 nlines += 1
                 if (line.find("Total") >= 0):
                     print(line)
                     

I need a text that is saved in the file after the line number obtained
With the above code I have access to the line number but I do not have access to some subsequent lines
How to access the next line value??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use next() to read:

path = 'C:\\Bot\\*.log' 
files = glob.glob(path) 
nlines = 0
for name in files: 
    try: 
        with open(name) as f:
            for line in f:
                 nlines += 1
                 if (line.find("Total") >= 0):
                      for i in range(6):
                          print(next(f))
                     
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading