Slow, word-by-word terminal printing in Python? [duplicate] Slow, word-by-word terminal printing in Python? [duplicate] unix unix

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.


import sysimport timefor c in gettysburg_address:  sys.stdout.write(c)  sys.stdout.flush()  # 110 baud:  time.sleep( 8./110 )  # 300 baud:  #  time.sleep( 8./300 )


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