unix - Slow, word-by-word terminal printing in Python? -


this question has answer here:

i'm writing python app involving database. hell of it, i'm including easter egg. if user decides nuke database, terminal, he'll prompted confirm simple (y/n). if types dlg2209tvx instead, lines scene of wargames print. doubt ever find unless through source, that's okay.

the problem printing lines plays scene way fast , ruins it. implemented timer between each character's lines slow things down, , it's better, still seems unnatural. there standardized way print each word or character out instead of doing lines @ time? or should start adding timers between words?

standardized? not know of. try this:

import random import sys import time  def slowprint(s):     c in s + '\n':         sys.stdout.write(c)         sys.stdout.flush() # defeat buffering         time.sleep(random.random() * 0.1)  slowprint('hello, world.') 

adjust 0.1 change maximum delay between characters, , add lengthy time.sleep()s between lines add more dramatic effect.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -