delay print in python 1

delay print in python

>>> import time
>>> import sys
>>> blah = "This is written slowly\n"
>>> for l in blah:
...   sys.stdout.write(l)
...   sys.stdout.flush()
...   time.sleep(0.2)
...
This is written slowly

Here is what the above code is Doing:
1. We import the time and sys modules.
2. We create a string called blah.
3. We loop through each character in blah.
4. We write the character to the screen.
5. We flush the output buffer.
6. We sleep for 0.2 seconds.

Similar Posts