alexa

Read a block in a large text file in python ?

Read a block in a large text file in python ?

You compare lines with "\n" at the ends. You also continue, when you find the start marker.

 beginOutput = false
with open("test.txt") as ff:
    for line in ff:
        if line.startswith('.Connect U5'):
            beginOutput = true

        if not beginOutput:
            continue

        if line.strip() == ".EndC":
            break

        print(line) 

Note the strip(). It's not the best solution, because it will strip all the lines in your file. Try to strip() only the lines which start with .EndC marker


209 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry