How to insert sleep into a list
<p>I am looking to create just a small module to implement the ability to text scroll. I've tried a few things so far and this is what I'm sitting on:</p>

<pre><code>from time import sleep

def text_scroll(x):
    x = x.split()
    #here is where I'd like to add the sleep function
    x = " ".join(x)

print x

text_scroll("hello world.")
</code></pre>

<p>With all this I am hoping to have it print "hello", sleep for a second, "world". The best I've gotten so far is it returning None instead of actually pausing.</p>

<p>If it is python 2.7, you can do the following, which is what volcano suggested.</p>

<pre><code>from time import sleep

def text_scroll(x):
    for word in x.split():
        print word,
        sleep(1)

text_scroll("Hello world")
</code></pre>

<p>This works because it splits the input into individual words and then prints them, sleeping between each word. The <code>print word,</code> is python 2.7 for print <code>word</code>, without a newline <code>,</code>.</p>

<p>Yours doesn't work for several reasons:</p>

<pre><code>def text_scroll(x):
    x = x.split()
    #here is where I'd like to add the sleep function
    x = " ".join(x)
</code></pre>

<p>this function doesn't do anything with the variable that it makes, and it mangles it:</p>

<pre><code>def text_scroll(x):
    x = x.split()                 # x = ["Hello", "world"]
    #here is where I'd like to add the sleep function
    x = " ".join(x)               # x = "Hello world"
</code></pre>

<p>It doesn't actually do anything with the result, so it gets thrown away. But it's also important to realize that because it is a <code>def</code>, it doesn't execute until it is called.</p>

<p>when you <code>print x</code>, <code>x</code> hasn't been set, so it should give you a <code>NameError: name 'x' is not defined</code></p>

<p>Finally, you call your function <code>text_scroll("hello world.")</code> which doesn't output anything, and it finishes.</p>

python sleep