forked from portfoliocourses/python-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard_error_output.py
More file actions
31 lines (26 loc) · 1.13 KB
/
standard_error_output.py
File metadata and controls
31 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
################################################################################
#
# Program: Output To Standard Error Example
#
# Description: Examples of ways to output to the standard error stream using
# Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=b09D3pG6jQc
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
import sys
import logging
# By default when using print() the string will be output to standard output
print("Standard output")
# If we import the sys module and supply file=sys.stderr as a 2nd argument then
# the string will be output to the standard error stream
print("Standard error", file=sys.stderr)
# We can also use the write() method of stderr in the sys module, but the
# be aware the write method does not put a newline at the end of the string
# we output as the print() function does by default.
sys.stderr.write("Error message\n")
# We can also use the logging module to output to standard error, here the
# warning function will write the "Warning message" to standard error.
logging.warning("Warning message")