Python By Example

stdin, stdout and stderr functions in System module

by Jiffin Joachim Gomez on 24th February 2017

This is a simple Python script to familiarize you with the system module (sys).

Python system module is something cool if you are really interested in python. As of now, I am only showing how you can use stdin, stdout and stderr functions. You can do a lot of cool stuffs using system module. The stdin function can be used to get input data from the python shell. The stdout function is used for outputs and stderr is used to show error messages.

#Import System module
import sys

print("Enter a number")
#input is read using stdin

#output printed using stdout
sys.stdout.write('This is stdout text\n')

#Error message is shown using stderr
sys.stderr.write('This is a stderror\n')

Program Output

Enter a number
This is stdout text
This is a stderror

Post a comment


Nothing the first to share wisdom.