unix - Slow, word-by-word terminal printing in Python? -
this question has answer here:
- how print 1 character @ time on 1 line? 3 answers
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
Post a Comment