Skip to content
Myr

Documentation improvements

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

authored by Kevin Yap · committed by Kevin Yap · parent dfb5e97 · Browse files · 1 file+10 added−10 removed
This commit

State

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

Diff stats

1 file+10 added−10 removed

  • other:+10 added−10 removed

1 file+10 added−10 removed

modified:docs/utils.rst+10 added-10 removed
10 unmodified lines
11Printing 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 is15works like the Python ``print`` statement or function. The main difference is16that it works the same in Python 2 and 3, it intelligently detects17misconfigured output streams, and will never fail (except in Python 3; for17misconfigured output streams, and it will never fail (except in Python 3; for18more information see :ref:`python3-limitations`).1920Example::21
1 unmodified line
2324 click.echo('Hello World!')2526Most importantly, it can print both Unicode and binary data, unlike the27builtin ``print`` function in Python 3, which cannot output any bytes. It28will, however, emit a trailing newline by default which needs to be29supressed by passing ``nl=False``::27built-in ``print`` function in Python 3, which cannot output any bytes. It28will, however, emit a trailing newline by default, which needs to be29suppressed by passing ``nl=False``::3031 click.echo(b'\xe2\x98\x83', nl=False)3233
10 unmodified lines
44is installed, then ANSI codes are intelligently handled.4546Primarily this means that:4748- click's echo function will automatically strip ANSI color codes if the49 stream is not connected to a terminal.50- the echo function will transparently connect to the terminal on48- click's :func:`echo` function will automatically strip ANSI color codes49 if the stream is not connected to a terminal.50- the :func:`echo` function will transparently connect to the terminal on51 Windows and translate ANSI codes to terminal API calls. This means52 that colors will work on Windows the same way they do on other53 operating systems.54
166 unmodified lines
221------------------222223Because filenames might not be Unicode, formatting them can be a bit224tricky. Generally, this is easier in Python 2 than on 3, as you can just225write the bytes to stdout with the print function, but in Python 3, you will226always need to operate in Unicode.225write the bytes to stdout with the ``print`` function, but in Python 3, you226will always need to operate in Unicode.227228The way this works with click is through the :func:`format_filename`229function. It does a best-effort conversion of the filename to Unicode and230will never fail. This makes it possible to use these filenames in the
106 unmodified lines