Skip to content

Commit 1f3fdc5

Browse files
committed
Recommend the use of double underscore throwaway variables
1 parent 8654487 commit 1f3fdc5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/writing/style.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,24 @@ Create an ignored variable
236236
~~~~~~~~~~~~~~~~~~~~~~~~~~
237237
238238
If you need to assign something (for instance, in :ref:`unpacking-ref`) but
239-
will not need that variable, use ``_``:
239+
will not need that variable, use ``__``:
240240
241241
.. code-block:: python
242242
243243
filename = 'foobar.txt'
244-
basename, _, ext = filename.rpartition()
244+
basename, __, ext = filename.rpartition()
245245
246246
.. note::
247247
248-
"``_``" is commonly used as an alias for the :func:`~gettext.gettext`
249-
function. If your application uses (or may someday use) :mod:`gettext`,
250-
you may want to avoid using ``_`` for ignored variables, as you may
251-
accidentally shadow :func:`~gettext.gettext`.
252-
248+
Many Python style guides recommend the use of a single underscore "``_``"
249+
for throwaway variables rather than the double underscore "``__``"
250+
recommended here. The issue is that "``_``" is commonly used as an alias
251+
for the :func:`~gettext.gettext` function, and is also used at the
252+
interactive prompt to hold the value of the last operation. Using a
253+
double underscore instead is just as clear and almost as convenient,
254+
and eliminates the risk of accidentally interfering with either of
255+
these other use cases.
256+
253257
Create a length-N list of the same thing
254258
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255259

0 commit comments

Comments
 (0)