mirror of
https://github.com/python/cpython.git
synced 2025-09-29 03:35:31 +00:00
add example function
This commit is contained in:
parent
57512588fa
commit
4199d603fe
1 changed files with 7 additions and 1 deletions
|
@ -784,7 +784,13 @@ always available.
|
||||||
The standard streams are in text mode by default. To write or read binary
|
The standard streams are in text mode by default. To write or read binary
|
||||||
data to these, use the underlying binary buffer. For example, to write bytes
|
data to these, use the underlying binary buffer. For example, to write bytes
|
||||||
to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``. Using
|
to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``. Using
|
||||||
:meth:`io.TextIOWrapper.detach` streams can be made binary by default.
|
:meth:`io.TextIOWrapper.detach` streams can be made binary by default. For
|
||||||
|
example, this function sets all the standard streams to binary: ::
|
||||||
|
|
||||||
|
def make_streams_binary():
|
||||||
|
sys.stdin = sys.stdin.detach()
|
||||||
|
sys.stdout = sys.stout.detach()
|
||||||
|
sys.stderr = sys.stderr.detach()
|
||||||
|
|
||||||
|
|
||||||
.. data:: __stdin__
|
.. data:: __stdin__
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue