79526549

Date: 2025-03-21 20:45:04
Score: 0.5
Natty:
Report link

Thanks to Adon and Timus I found two solutions that work even faster within my class.

    def read_file(self, start):
        self.readstart = start

        with open(self.filename, "r") as f:
            f.seek(self.readstart)
            line = f.readline()
            content = ""
            while line:
                content += line.strip()
                line = f.readline()
                if line.strip().startswith('>'): 
                    self.content = content
                    return

and

    def alt_read_file(self, start, end):
        with open(self.filename, "r") as f:
            f.seek(start)
            self.content = re.sub(r"\s+", "", f.read(end-start))

The answer to my initial question is that probably by string concatenation of a class variable each time memory allocation is renewed by the Python interpreter.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: user1491229