stdin and stdout are file-like objects provided by the OS. In general, when a program is run in an interactive session, stdin is keyboard input and stdout is the user's tty, but the shell can be used to redirect them from normal files or piped output from and input to other programs.

input() is used to prompt the user for typed input. In the case of something like a programming puzzle, it's normally assumed that stdin is redirected from a data file, and when the input format is given it's usually best to use sys.stdin.read() rather than prompting for input with input(). input() is intended for interactive user input, it can display a prompt (on sys.stdout) and use the GNU readline library (if present) to allow line editing, etc.

print() is, indeed, the most common way of writing to stdout. There's no need to do anything special to specify the output stream. print() writes to sys.stdout if no alternate file is given to it as a file= parameter.

Answer from Wooble on Stack Overflow
🌐
AskPython
askpython.com › home › python – stdin, stdout, and stderr
Python - stdin, stdout, and stderr - AskPython
February 16, 2023 - Standard input – This is the file-handle that a user program reads to get information from the user. We give input to the standard input (stdin). Standard output – The user program writes normal information to this file-handle. The output is returned via the Standard output (stdout)....
Top answer
1 of 5
19

stdin and stdout are file-like objects provided by the OS. In general, when a program is run in an interactive session, stdin is keyboard input and stdout is the user's tty, but the shell can be used to redirect them from normal files or piped output from and input to other programs.

input() is used to prompt the user for typed input. In the case of something like a programming puzzle, it's normally assumed that stdin is redirected from a data file, and when the input format is given it's usually best to use sys.stdin.read() rather than prompting for input with input(). input() is intended for interactive user input, it can display a prompt (on sys.stdout) and use the GNU readline library (if present) to allow line editing, etc.

print() is, indeed, the most common way of writing to stdout. There's no need to do anything special to specify the output stream. print() writes to sys.stdout if no alternate file is given to it as a file= parameter.

2 of 5
5

When you run your Python program, sys.stdin is the file object connected to standard input (STDIN), sys.stdout is the file object for standard output (STDOUT), and sys.stderr is the file object for standard error (STDERR).

Anywhere in the documentation you see references to standard input, standard output, or standard error, it is referring to these file handles. You can access them directly (sys.stdout.write(...), sys.stdin.read() etc.) or use convenience functions that use these streams, like input() and print().

For the Spotify puzzle, the easiest way to read the input would be something like this:

import sys
data = sys.stdin.read()

After these two lines the input for your program is now in the str data.

Discussions

Confused about stdin and stdout
stdin, stdout and stderr have nothing to do with python specifically. These are what we call the main pathways for data to flow in and out of any CLI program. As a beginner, you don't need to worry about them at all, because python wraps them in easy to use input() (for stdin) and print() (for stdout) functions. But for advanced users and very rare usecases we can use the sys modules to access them. https://en.wikipedia.org/wiki/Standard_streams More on reddit.com
🌐 r/learnpython
6
1
September 16, 2022
python - Stdin and Stdout - Stack Overflow
Can someone explain stdin and stdout? I don't understand what is the difference between using these two objects for user input and output as opposed to print and raw_input. Perhaps there is some vi... More on stackoverflow.com
🌐 stackoverflow.com
Forcing sys.stdin/stdout/stderr encoding/newline behavior programmatically
I learned the hard way that Python does not always use UTF-8 for sys.stdin/stderr/stdout. In order to make my own tools always work properly as pipes using UTF-8 encoding and also handle new lines properly (like open would do by default), I would like to set this programmatically for all Python ... More on discuss.python.org
🌐 discuss.python.org
6
0
May 2, 2022
How can I continuously send and recieve stdin and stdout with a running process?
Things I would do before I tried to do this: Import getInput.py and use its functions directly Copy and paste code out of getInput.py and re-write it to work in my code Python using subprocess to call Python is pointless. If the issue is that getInput.py isn't written in a way that makes it a callable Python module, then re-write it so it is. More on reddit.com
🌐 r/learnpython
9
4
April 7, 2023
🌐
Python Guides
pythonguides.com › python-stderr-stdin-and-stdout
Python – stdin stdout and stderr [6 Examples] - Python Guides
September 3, 2025 - When I run this, the normal message goes to output.log, and the error goes to error.log. In real-world applications, I often need to run external commands (like shell commands) from Python. In such cases, the subprocess module is my go-to. ... import subprocess # Example 4: Using subprocess with stdin, stdout, and stderr process = subprocess.Popen( ["python", "-c", "print('Hello from subprocess!'); raise ValueError('Oops!')"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) out, err = process.communicate() print("Captured stdout:", out) print("Captured stderr:", err)
🌐
Medium
medium.com › @hhtg250 › stdin-stdout-flush-and-buffering-in-python-e747b85cb6ae
Understanding stdin, stdout, flush(), and Buffering in Python | by Ahmed Nabil - أحمد نبيل | Medium
July 25, 2024 - In Python, handling input and output efficiently is crucial for various applications, from simple scripts to complex data processing. This article delves into the concepts of stdin, stdout, flush(), and buffering, explaining how they work and when to use them.
🌐
DevDungeon
devdungeon.com › content › using-stdin-stdout-and-stderr-python
Using stdin, stdout, and stderr in Python | DevDungeon
February 15, 2020 - To pipe the standard output of one program to the standard input of your Python program, you can do it like this: ... The dunder properties sys.__stdin__, sys.__stdout__ and sys.__stderr__ always contain references to the original streams.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-print-to-stderr-and-stdout-in-python
How to print to stderr and stdout in Python? - GeeksforGeeks
July 12, 2025 - In Python, whenever we use print() the text is written to Python’s sys.stdout, whenever input() is used, it comes from sys.stdin, and whenever exceptions occur it is written to sys.stderr. We can redirect the output of our code to a file other than stdout. But you may be wondering why one should do this?
🌐
Wellsr
wellsr.com › python › python-stdin-stdout-stderr-with-sys-module
Using Python stdin, stdout, and stderr with the sys Module - wellsr.com
August 9, 2019 - [input] is the output of a command generating text output to stdout, | is the pipe operator directing the input to Python, > out.log directs Python’s stdout (the output of the script) to the file out.log, and 2> err.log directs Python’s stderr to the file err.log. We can use these pipeline tools in our own Python script, like this: import sys for line in sys.stdin: # Process stdin print("[stdout output]") # Print statements go to stdout print("[stderr output]", file=sys.stderr) # (Python Ver.
🌐
Plain English
python.plainenglish.io › stdin-stdout-and-stderr-for-mortals-3b2d0f3b8f42
stdin, stdout, and stderr For Mortals | by Rahul Beniwal | Python in Plain English
July 25, 2024 - ... stdin (0): This is typically used for reading input data. For example, when you use functions like scanf() in C or input() in Python, they read data from stdin. stdout (1): This is used for normal standard output.
🌐
Quora
quora.com › What-is-the-function-of-STDIN-and-STDOUT-in-Python
What is the function of STDIN and STDOUT in Python? - Quora
Answer (1 of 3): First off, the three standard input streams - standard input (STDIN), standard output (STDOUT) and standard error (STDERR) - are not original or unique to the Python programming language.
🌐
YouTube
youtube.com › neuralnine
Understanding stdin, stdout, stderr in Python - YouTube
Today we learn about the standard streams stdin, stdout and stderr as well as how to use them in Python.◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾📚 Programming Books & Merch 📚🐍 Th...
Published   August 30, 2023
Views   12K
🌐
O'Reilly
oreilly.com › library › view › python-in-a › 0596001886 › re118.html
stdin, stdout, stderr - Python in a Nutshell [Book]
March 3, 2003 - Namestdin, stdout, stderr Synopsis stdin , stdout, and stderr are predefined file objects that correspond to Python’s standard input, output, and error streams. You can rebind... - Selection from Python in a Nutshell [Book]
Author   Alex Martelli
Published   2003
Pages   656
🌐
GeeksforGeeks
geeksforgeeks.org › python › take-input-from-stdin-in-python
Take input from stdin in Python - GeeksforGeeks
July 12, 2025 - There are a number of ways in which we can take input from stdin in Python. ... First we need to import sys module. sys.stdin can be used to get input from the command line directly. It used is for standard input. It internally calls the input() method. Furthermore, it, also, automatically adds '\n' after each sentence. ... import sys for line in sys.stdin: if 'q' == line.rstrip(): break print(f'Input : {line}') print("Exit") ... The input() can be used to take input from the user while executing the program and also in the middle of the execution.
🌐
Python
docs.python.org › 3 › library › sys.html
sys — System-specific parameters and functions
Non-character devices such as disk files and pipes use the system locale encoding (i.e. the ANSI codepage). Non-console character devices such as NUL (i.e. where isatty() returns True) use the value of the console input and output codepages at startup, respectively for stdin and stdout/stderr.
🌐
NetworkLessons
notes.networklessons.com › home › python › python print function
Python stdin, stdout, stderr - Notes
February 27, 2020 - And then try these examples. ... This tells Python to execute the function. We don’t see anything on our screen, but this produces an invisible newline character, which shows up as a blank line on your screen.
🌐
docs.python.org
docs.python.org › 3 › library › subprocess.html
subprocess — Subprocess management
When used, the internal Popen object ... and the stdin argument may not be used as well. If check is true, and the process exits with a non-zero exit code, a CalledProcessError exception will be raised. Attributes of that exception hold the arguments, the exit code, and stdout and stderr ...