Print Status Messages

General Information

Printing status messages in Python scripts involves flushing the standard output buffer.

If the buffer is not flushed, Python will decide on its own when to flush it, resulting in sporadic large amounts of output. (Not useful for command line scripts/programs)


  • Python 2 or 3


Using the code snippet.

chmod +x print-status-msg.py

The Code

# Import Modules
# Future print function capabilities
from __future__ import print_function
# sys: for stdout print buffer flush
import sys
# time: for sleeping
import time
#-- Example status message code --#
print("Doing some work", end='')
# Loop from 0 to 59
for count in range(59):
  # Print a period '.' with no newline
  print('.', end='')
  # Flush the stdout buffer to display it immediately to the console
  # sleep for 1 second

  • python_wiki/print_status_messages.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)