python_wiki:print_status_messages

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python_wiki:print_status_messages [2017/09/16 13:56]
billdozor created
python_wiki:print_status_messages [2019/05/25 23:50]
Line 1: Line 1:
-====== 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) 
- 
-**Checklist** 
-  * Python 2 or 3 
- 
----- 
- 
-====== Usage ====== 
- 
-Using the example snippet. 
-<code bash> 
-chmod +x print-status-msg.py 
-./print-status-msg.py 
-</code> 
- 
----- 
- 
-====== The Code ====== 
- 
-<code python print-status-msg.py> 
-#!/usr/bin/python 
-#======================= 
-# 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 
-  sys.stdout.flush() 
- 
-  # sleep for 1 second 
-  time.sleep(1) 
- 
-print("[COMPLETE]") 
-</code> 
- 
----- 
  
  • python_wiki/print_status_messages.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)