From 1f3fdc51cdd710d15c261a525f1885bf788760df Mon Sep 17 00:00:00 2001 From: ncoghlan Date: Wed, 30 May 2012 21:43:24 +1000 Subject: [PATCH] Recommend the use of double underscore throwaway variables --- docs/writing/style.rst | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/writing/style.rst b/docs/writing/style.rst index abd485f..91f1a1d 100644 --- a/docs/writing/style.rst +++ b/docs/writing/style.rst @@ -236,20 +236,24 @@ Create an ignored variable ~~~~~~~~~~~~~~~~~~~~~~~~~~ If you need to assign something (for instance, in :ref:`unpacking-ref`) but -will not need that variable, use ``_``: +will not need that variable, use ``__``: .. code-block:: python filename = 'foobar.txt' - basename, _, ext = filename.rpartition() + basename, __, ext = filename.rpartition() .. note:: - "``_``" is commonly used as an alias for the :func:`~gettext.gettext` - function. If your application uses (or may someday use) :mod:`gettext`, - you may want to avoid using ``_`` for ignored variables, as you may - accidentally shadow :func:`~gettext.gettext`. - + Many Python style guides recommend the use of a single underscore "``_``" + for throwaway variables rather than the double underscore "``__``" + recommended here. The issue is that "``_``" is commonly used as an alias + for the :func:`~gettext.gettext` function, and is also used at the + interactive prompt to hold the value of the last operation. Using a + double underscore instead is just as clear and almost as convenient, + and eliminates the risk of accidentally interfering with either of + these other use cases. + Create a length-N list of the same thing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 1.8.0.2