I made a type() function which functions similarly to print except it types character by character. The problem is, when I try to implement multiple str arguments it just prints everything at once.
The code I used originally was:
import sys
import time
def type(text):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.05)
print()
In order to add more str arguments, I did:
import sys
import time
def type(*text):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.05)
print()
In practice, however, it usually just prints everything at once, like a normal print function.
Any pointers?
>Solution :
If text is a list, and the length of it varies, you can do:
def type(text):
for string in text:
for char in string:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.05)
print()
So you loop through the lists for each string, and for each string you loop through all the characters.