Similar to my last question: Delayed text (Need it more efficiently delayed) C++. I need to make more efficiently delayed text in python. I tried to alter the other function to make it work but I couldn't get it to work.
2 Answers
def delay_print(text, delay):
for i in text:
time.sleep(delay)
print(i, end='')
sys.stdout.flush()
print()
This is just loops through the given text and uses end='' to not print a new line until the loop finishes
7 Comments
Matthias
Why the name
sPrint for the function? Why not stick to the Style Guide for Python Code and call the function delayed_print or something like that?andria_girl
I actually didn't know there was a naming convention, I usually just name things like that. Thanks for showing me that though
ActiveGaming
how do I call the function, I figured out with the other one it is poketext("Text Here") but I can't seem to figure it out with this one
andria_girl
Seriously?? You call it with your string and your delay, delay_print("here is a string but you can use a variable too", 0.05)
andria_girl
0.05 is the time in seconds between each character print
|
printandsleep. Where's your problem?