Frage

I already know how to print a file to stdout using shutil.copyfileobj, it's done like this:

with open('filename.extension', 'r') as file:
    shutil.copyfileobj(file, sys.stdout)

Unfortunately for me, when it does this, it prints the whole file all at once. I don't want it to do this. I want it to gradually print line after line, with a pause in between printing each line using time.sleep(). Is there any way I can achieve this?

War es hilfreich?

Lösung

Try something like this:

with open('filename.extension', 'r') as file:
    for line in file:
        print(line)
        time.sleep(1)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top