Animated text funtion only working for certain strings
<p>I am attempting to make a function that displays animated text in Python</p>

<pre><code>import sys
def anitext(str):
    for char in str:
            sys.stdout.write(char)
            time.sleep(textspeed)
    print ("")
</code></pre>

<p>This function is working for strings such as</p>

<pre><code>anitext ("String")
</code></pre>

<p>And for sole variables such as</p>

<pre><code>name = ("Stack")
anitext (name)
</code></pre>

<p>But will not work for input statements, or conjoined statements like</p>

<pre><code>anitext (name, "This is a string")
</code></pre>

<p>Is there any way for this "Anitext" function to work on statements that are not just plain strings?</p>

<p><em>- Olli E</em></p>

<p>You just need to use argument unpacking. See <a href="https://docs.python.org/3/tutorial/controlflow.html#arbitrary-argument-lists" rel="nofollow">Arbitrary Argument Lists</a> in the official Python tutorial.</p>

<pre><code>import sys
import time

textspeed = 0.2

def anitext(*args):
    for s in args:
        for char in s:
            sys.stdout.write(char)
            sys.stdout.flush()
            time.sleep(textspeed)
        print("")

anitext("String", "Another string", "More stuff")
</code></pre>

<p>I've made a couple of other changes to your script. The <code>sys.stdout.flush()</code> call ensures that the characters are actually printed one at a time; most terminals will buffer whole lines of text, so you wouldn't actually see the animation happening.</p>

<p>Also, I use <code>s</code> for the name of the current string being animated. You should not use <code>str</code> as a variable name as that shadows the built-in <code>str</code> type. That makes your code confusing to read and can also lead to subtle bugs.  </p>

python function variables