0

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
  • Sounds simple. Loop over every character in the text. In the loop body use print and sleep. Where's your problem? Commented Mar 21, 2017 at 21:25
  • I don't know how to do that, could you send a code example. I just started python yesterday. Commented Mar 21, 2017 at 21:30

2 Answers 2

1
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

Sign up to request clarification or add additional context in comments.

7 Comments

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?
I actually didn't know there was a naming convention, I usually just name things like that. Thanks for showing me that though
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
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)
0.05 is the time in seconds between each character print
|
0
import time

msg = "helloworld"
for char in msg:
    print char
    time.sleep(1) #seconds

Did you try something like this?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.