How to Flush the Output of the Python Print Function

Do you want to build a compact visual progress indicator for your Python script using print(), but your output doesn’t show up when you’d expect it to? Or are you piping the logs of your script to another application, but you can’t manage to access them in real time? In both cases, data buffering is the culprit, and you can solve your troubles by flushing the output of print().

In this tutorial, you’ll learn how to:

  • Flush the output data buffer explicitly using the flush parameter of print()
  • Change data buffering for a single function, the whole script, and even your entire Python environment
  • Determine when you need to flush the data buffer explicitly and when that

     

     

     

    To finish reading, please visit source site