Home

sysstdin

sys.stdin is a standard component of Python’s runtime that represents the program’s standard input stream. It is exposed via the sys module as a global, file-like object that can be read from just as a file. In CPython, sys.stdin is a TextIOWrapper around a buffered binary stream, providing a convenient text interface for reading text data. Its text encoding is typically derived from the system locale and is accessible through attributes like sys.stdin.encoding; many aspects of its behavior can be adjusted in modern Python versions using reconfigure.

As a text stream, sys.stdin supports common file-like operations such as read, readline, and readlines, and it

Usage and behavior: sys.stdin reads data supplied to the program from the console, a redirected file, or

Reassignment and compatibility: sys.stdin is a global resource and can be reassigned to another file-like object,

is
also
iterable
line
by
line.
The
built-in
input()
function
reads
a
line
from
sys.stdin,
strips
the
trailing
newline,
and
returns
it
as
a
string.
For
binary
data,
the
underlying
raw
buffer
can
be
accessed
via
sys.stdin.buffer,
which
provides
a
binary
interface
separate
from
the
text
wrapper.
a
piped
command.
When
input
is
redirected
(for
example,
program
<
file.txt
or
a
pipe
from
another
process),
sys.stdin
reads
from
that
source
instead
of
a
terminal.
environments
such
as
integrated
development
environments
or
notebooks
may
alter
or
stub
sys.stdin,
affecting
how
input
is
received.
though
doing
so
can
affect
other
parts
of
the
program.
For
text
processing,
rely
on
sys.stdin
for
reading
input
data
and
consider
sys.stdin.buffer
for
raw
bytes.