Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: Print to Standard Error

📅 2010-Jan-20 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

 

Printing error messages (as opposed to diagnostic log messages) to the Standard Error stream (sys.stderr) is a good habit. This is done by passing file=std.stderr to [print](http://docs.python.org/library/functions.html#print)(). In Eclipse, the sys.stderr messages are printed in a different color (red above) which is great to spot the error messages.

import sys
print("Checking oxygen tank", i, "... FAIL!", file=sys.stderr)

Tried with: Python 3.2