Slow, word-by-word terminal printing in Python? [duplicate]
Standardized? Not that I know of. But try this:
import randomimport sysimport timedef slowprint(s): for c in s + '\n': sys.stdout.write(c) sys.stdout.flush() # defeat buffering time.sleep(random.random() * 0.1)slowprint('Hello, world.')
Adjust the 0.1
to change the maximum delay between characters, and add lengthy time.sleep()
s between lines to add more dramatic effect.
You can also try curses.delay_output()
:
In [48]: import cursesIn [49]: for x in "foo bar": sys.stdout.write(x) #prints each char with a delay of 100ms curses.delay_output(100) ....: foo bar