python/dist/src/Lib doctest.py,1.33,1.34

Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2601/Lib Modified Files: doctest.py Log Message: Patch #932930: suggest the use of rawstrings for backslashes. Index: doctest.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** doctest.py 12 Feb 2004 17:35:06 -0000 1.33 --- doctest.py 31 May 2004 19:01:00 -0000 1.34 *************** *** 5,9 **** # Provided as-is; use at your own risk; no warranty; no promises; enjoy! ! """Module doctest -- a framework for running examples in docstrings. NORMAL USAGE --- 5,9 ---- # Provided as-is; use at your own risk; no warranty; no promises; enjoy! ! r"""Module doctest -- a framework for running examples in docstrings. NORMAL USAGE *************** *** 201,215 **** tracebacks are captured via a different means). ! + If you continue a line via backslashing in an interactive session, or for ! any other reason use a backslash, you need to double the backslash in the ! docstring version. This is simply because you're in a string, and so the ! backslash must be escaped for it to survive intact. Like: ! >>> if "yes" == \\ ! ... "y" + \\ ! ... "es": # in the source code you'll see the doubled backslashes ! ... print 'yes' ! yes The starting column doesn't matter: --- 201,224 ---- tracebacks are captured via a different means). ! + If you continue a line via backslashing in an interactive session, ! or for any other reason use a backslash, you should use a raw ! docstring, which will preserve your backslahses exactly as you type ! them: ! >>> def f(x): ! ... r'''Backslashes in a raw docstring: m\n''' ! >>> print f.__doc__ ! Backslashes in a raw docstring: m\n ! ! Otherwise, the backslash will be interpreted as part of the string. ! E.g., the "\n" above would be interpreted as a newline character. ! Alternatively, you can double each backslash in the doctest version ! (and not use a raw string): + >>> def f(x): + ... '''Backslashes in a raw docstring: m\\n''' + >>> print f.__doc__ + Backslashes in a raw docstring: m\n + The starting column doesn't matter:
participants (1)
-
loewis@users.sourceforge.net