Python code, Time delay on console text -
i'm making code should print text on console , every letter should came little delay. i've tried this
from time import sleep print "h", sleep(0.1), "e", sleep(0.1), "l", sleep(0.1), "l", sleep(0.1), "o"
but puts random "none" there. should do? please :?:
sleep
returns none, gets printed. print
each char without newline , sleep:
import sys time import sleep c in "hello": print c, # note comma sleep(0.1) print # final newline
but avoid spaces inbetween, you'll have this:
import sys time import sleep c in "hello": sys.stdout.write(c) sleep(0.1) sys.stdout.write('\n')
depeding on environment, might need flush stdout buffer:
import sys time import sleep c in "hello": sys.stdout.write(c) sys.stdout.flush() sleep(0.1) sys.stdout.write('\n') sys.stdout.flush()
Comments
Post a Comment