I am fairly new to python and have been trying to make a program that prints a string one character at a time. I was originally using time.sleep()
for the delay but it was very inconsistent and looked choppy. I now use time.clock()
and compare it after the character is printed. It works better but is still choppy at times. Is there a very consistent method of timekeeping in python?
My code:
def typePrint(string, sec):
from time import clock
for char in string:
strt = clock()
print(char, end='', flush=True)
while clock() - strt < sec:
pass
print()