Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: Print to Standard Error

📅 2010-Jan-20 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ python, stderr ⬩ 📚 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]( 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

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧