TechplexEngineer TechplexEngineer - 1 year ago 139
Python Question

printing slowly (Simulate typing)

I am trying to make a textual game in python. All goes well however, I would like to make a function that will allow me to print something to the terminal, but in a fashion hat looks like typing.

Currently I have:

def print_slow(str):
for letter in str:
print letter,


The output is:

j u n k

Is there a way to get rid of the spaces between the letters?

Answer Source

In Python 2.x you can use sys.stdout.write instead of print:

for letter in str:

In Python 3.x you can set the optional argument end to the empty string:

print(letter, end='')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download