Created
March 25, 2013 09:18
-
-
Save santosh/5235922 to your computer and use it in GitHub Desktop.
This script demonstrate the `flush` argument of print() function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
from __future__ import print_function | |
from time import sleep | |
string = "The words in this sentence should appear letter by letter." | |
print("Please wait if you don't see another sentence appearing below.", end="\n\n") | |
for characters in string: | |
# If flush disabled the another line will appear at once and not char by char. | |
print(characters, end="", flush=True) | |
sleep(.1) |
@shy-tan @Gwanza I tested it on powershell and it works fine, but I was using Jupyter before and it wasn't working on Jupyter.
I tried the same on Pycharm it doesn't work, maybe Pycharm doesn't support flush. It only works when you use it on the terminal. Try running the same file through the terminal
No difference with or without flush. Python 3.9 Windows 10 Pro
I agree with this
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No difference with or without flush.
Python 3.9
Windows 10 Pro