Animated text funtion only working for certain strings
Question: I am attempting to make a function that displays animated text in Python

    
    
    import sys
    def anitext(str):
        for char in str:
                sys.stdout.write(char)
                time.sleep(textspeed)
        print ("")
    

This function is working for strings such as

    
    
    anitext ("String")
    

And for sole variables such as

    
    
    name = ("Stack")
    anitext (name)
    

But will not work for input statements, or conjoined statements like

    
    
    anitext (name, "This is a string")
    

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

_\- Olli E_


Answer: You just need to use argument unpacking. See [Arbitrary Argument
Lists](https://docs.python.org/3/tutorial/controlflow.html#arbitrary-argument-
lists) in the official Python tutorial.

    
    
    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")
    

I've made a couple of other changes to your script. The `sys.stdout.flush()`
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.

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

