What does sys.stdout.flush() do?

John Gordon gordon at panix.com
Fri Aug 23 10:06:51 EDT 2013


In <c34119f1-3e04-419d-8dd9-07dd4c648886 at googlegroups.com> "D. Xenakis" <gouzounakis at hotmail.com> writes:

> Can someone post here a script example with sys.stdout.flush(), where in
> case i commented that i could understand what the difference really would
> be?

Depending what sys.stdout is connected to (a file, the screen, a pipe,
etc.), data doesn't necessarily get written right away.  In particular,
screen output often waits until it receives a newline before displaying
anything.

flush() makes sure it all gets written *right now*.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list