Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
a8ff01ca
Kaydet (Commit)
a8ff01ca
authored
Ara 15, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #13597: Improve documentation of standard streams.
üst
e0e2735f
7158e062
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
19 deletions
+30
-19
sys.rst
Doc/library/sys.rst
+30
-19
No files found.
Doc/library/sys.rst
Dosyayı görüntüle @
a8ff01ca
...
@@ -941,31 +941,42 @@ always available.
...
@@ -941,31 +941,42 @@ always available.
stdout
stdout
stderr
stderr
:term:`File objects <file object>` corresponding to the interpreter's standard
:term:`File objects <file object>` used by the interpreter for standard
input, output and error streams. ``stdin`` is used for all interpreter input
input, output and errors:
except for scripts but including calls to :func:`input`. ``stdout`` is used
for the output of :func:`print` and :term:`expression` statements and for the
* ``stdin`` is used for all interactive input (including calls to
prompts of :func:`input`. The interpreter's own prompts
:func:`input`);
and (almost all of) its error messages go to ``stderr``. ``stdout`` and
* ``stdout`` is used for the output of :func:`print` and :term:`expression`
``stderr`` needn't be built-in file objects: any object is acceptable as long
statements and for the prompts of :func:`input`;
as it has a :meth:`write` method that takes a string argument. (Changing these
* The interpreter's own prompts and its error messages go to ``stderr``.
objects doesn't affect the standard I/O streams of processes executed by
:func:`os.popen`, :func:`os.system` or the :func:`exec\*` family of functions in
By default, these streams are regular text streams as returned by the
the :mod:`os` module.)
:func:`open` function. Their parameters are chosen as follows:
The standard streams are in text mode by default. To write or read binary
* The character encoding is platform-dependent. Under Windows, if the stream
data to these, use the underlying binary buffer. For example, to write bytes
is interactive (that is, if its :meth:`isatty` method returns True), the
to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``. Using
console codepage is used, otherwise the ANSI code page. Under other
:meth:`io.TextIOBase.detach` streams can be made binary by default. This
platforms, the locale encoding is used (see :meth:`locale.getpreferredencoding`).
Under all platforms though, you can override this value by setting the
:envvar:`PYTHONIOENCODING` environment variable.
* When interactive, standard streams are line-buffered. Otherwise, they
are block-buffered like regular text files. You can override this
value with the :option:`-u` command-line option.
To write or read binary data from/to the standard streams, use the
underlying binary :data:`~io.TextIOBase.buffer`. For example, to write
bytes to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``. Using
:meth:`io.TextIOBase.detach`, streams can be made binary by default. This
function sets :data:`stdin` and :data:`stdout` to binary::
function sets :data:`stdin` and :data:`stdout` to binary::
def make_streams_binary():
def make_streams_binary():
sys.stdin = sys.stdin.detach()
sys.stdin = sys.stdin.detach()
sys.stdout = sys.stdout.detach()
sys.stdout = sys.stdout.detach()
Note that the streams can be replaced with objects (like
Note that the streams may be replaced with objects (like :class:`io.StringIO`)
:class:`io.StringIO`) that do not support the
that do not support the :attr:`~io.BufferedIOBase.buffer` attribute or the
:attr:`~io.BufferedIOBase.buffer` attribute or the
:meth:`~io.BufferedIOBase.detach` method and can raise :exc:`AttributeError`
:meth:`~io.BufferedIOBase.detach` method and can raise :exc:`AttributeError`
or :exc:`io.UnsupportedOperation`.
or :exc:`io.UnsupportedOperation`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment