Skip to content
Myr

Updated docs for streams

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 002c38d · Browse files · 2 files+50 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+50 added−0 removed

  • other:+50 added−0 removed

2 files+50 added−0 removed

modified:docs/index.rst+1 added
55 unmodified lines
56 setuptools57 complex58 advanced59 testing60 utils61 python36263API Reference64-------------
8 unmodified lines
added:docs/utils.rst+49 added
1Utilities2=========34.. currentmodule:: click56Besides the functionality that Click provides to interface with argument7parsing and handling, it also provides a bunch of addon functionality that8is useful for writing command line utilities.91011Priting to Stdout12-----------------1314The most obvious helper is the :func:`echo` function which in many ways15works like the Python print statement or function. The main difference is16that it works the same on Python 2 and 3 and it intelligently detects17misconfigured output streams and will never fail (except on Python 3, for18more information see :ref:`python3-limitations`).1920Example::2122 import click2324 click.echo('Hello World!')252627Standard Streams28----------------2930For command line utilities it's very important to get access to input and31output streams reliably. Python generally provides access to these32streams through ``sys.stdout`` and friends, but unfortunately there are33API differences between 2.x and 3.x. Especially in regards to how these34streams respond to unicode and binary data there are wide differences.3536Because of this click provides the :func:`get_binary_stream` and37:func:`get_text_stream` which produce consistent results with different38Python versions and for widely misconfigured terminals.3940The end result is that these functions will always reutrn a functional41stream object (except in very odd cases on Python 3, see42:ref:`python3-limitations`).4344Example::4546 import click4748 stdin_text = click.get_text_stream('stdin')49 stdout_binary = click.get_binary_stream('stdout')