[Python] Python for i loop slowing down gradually over time

Discussão em 'Python' iniciado por Stack, Novembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    this is the entire script and its running on its own. This script cycles trough thousands of .txt files and just prints their contents. Though it quickly starts to slow down.

    First they print at a very high rate but after a short while it slows to maybe 4 prints per second

    the txts get printed in the cmd

    count=1
    nofframes=35952


    for i in range(0, nofframes):
    f = open("C:/insert/file/location/print"+str(count)+".txt", 'r')
    c=f.read()


    line_count = c.count('\n')
    print (line_count)

    for i in range(0,line_count):
    end = end+"\033[F"

    print(c, end=str(end))

    f.close()
    count=count+1


    i've tried to make sure the f.close() function actually closes the file, but not sure how to debug that.

    Continue reading...

Compartilhe esta Página