@@ -226,11 +226,11 @@ \subsection{What About Exceptions?}
226226traceback itself. For example:
227227
228228\begin {verbatim }
229- >>> [1, 2, 3].remove(42)
230- Traceback (most recent call last):
231- File "<stdin>", line 1, in ?
232- ValueError: list.remove(x): x not in list
233- >>>
229+ >>> [1, 2, 3].remove(42)
230+ Traceback (most recent call last):
231+ File "<stdin>", line 1, in ?
232+ ValueError: list.remove(x): x not in list
233+ >>>
234234\end {verbatim }
235235
236236Note that only the exception type and value are compared (specifically,
@@ -257,26 +257,27 @@ \subsection{How are Docstring Examples Recognized?}
257257the business of guessing what you think a tab means).
258258
259259\begin {verbatim }
260- >>> # comments are ignored
261- >>> x = 12
262- >>> x
263- 12
264- >>> if x == 13:
265- ... print "yes"
266- ... else:
267- ... print "no"
268- ... print "NO"
269- ... print "NO!!!"
270- ...
271- no
272- NO
273- NO!!!
274- >>>
260+ >>> # comments are ignored
261+ >>> x = 12
262+ >>> x
263+ 12
264+ >>> if x == 13:
265+ ... print "yes"
266+ ... else:
267+ ... print "no"
268+ ... print "NO"
269+ ... print "NO!!!"
270+ ...
271+ no
272+ NO
273+ NO!!!
274+ >>>
275275\end {verbatim }
276276
277- Any expected output must immediately follow the final \code {"> >>"} or
278- \code {"..."} line containing the code, and the expected output (if any)
279- extends to the next \code {"> >>"} or all-whitespace line.
277+ Any expected output must immediately follow the final
278+ \code {'>\code {>}>~'} or \code {'...~'} line containing the code, and
279+ the expected output (if any) extends to the next \code {'>\code {>}>~'}
280+ or all-whitespace line.
280281
281282The fine print:
282283
@@ -310,8 +311,9 @@ \subsection{How are Docstring Examples Recognized?}
310311 1.0
311312\end {verbatim }
312313
313- and as many leading whitespace characters are stripped from the expected
314- output as appeared in the initial "> >>" line that triggered it.
314+ and as many leading whitespace characters are stripped from the
315+ expected output as appeared in the initial \code {'>\code {>}>~'} line
316+ that triggered it.
315317\end {itemize }
316318
317319\subsection {Warnings }
@@ -349,57 +351,57 @@ \subsection{Warnings}
349351% Hey! What happened to Monty Python examples?
350352% Tim: ask Guido -- it's his example!
351353\begin {verbatim }
352- >>> foo()
353- {"Hermione": "hippogryph", "Harry": "broomstick"}
354- >>>
354+ >>> foo()
355+ {"Hermione": "hippogryph", "Harry": "broomstick"}
356+ >>>
355357\end {verbatim }
356358
357359is vulnerable! One workaround is to do
358360
359361\begin {verbatim }
360- >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
361- 1
362- >>>
362+ >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
363+ 1
364+ >>>
363365\end {verbatim }
364366
365367instead. Another is to do
366368
367369\begin {verbatim }
368- >>> d = foo().items()
369- >>> d.sort()
370- >>> d
371- [('Harry', 'broomstick'), ('Hermione', 'hippogryph')]
370+ >>> d = foo().items()
371+ >>> d.sort()
372+ >>> d
373+ [('Harry', 'broomstick'), ('Hermione', 'hippogryph')]
372374\end {verbatim }
373375
374376There are others, but you get the idea.
375377
376378Another bad idea is to print things that embed an object address, like
377379
378380\begin {verbatim }
379- >>> id(1.0) # certain to fail some of the time
380- 7948648
381- >>>
381+ >>> id(1.0) # certain to fail some of the time
382+ 7948648
383+ >>>
382384\end {verbatim }
383385
384386Floating-point numbers are also subject to small output variations across
385387platforms, because Python defers to the platform C library for float
386388formatting, and C libraries vary widely in quality here.
387389
388390\begin {verbatim }
389- >>> 1./7 # risky
390- 0.14285714285714285
391- >>> print 1./7 # safer
392- 0.142857142857
393- >>> print round(1./7, 6) # much safer
394- 0.142857
391+ >>> 1./7 # risky
392+ 0.14285714285714285
393+ >>> print 1./7 # safer
394+ 0.142857142857
395+ >>> print round(1./7, 6) # much safer
396+ 0.142857
395397\end {verbatim }
396398
397399Numbers of the form \code {I/2.**J} are safe across all platforms, and I
398400often contrive doctest examples to produce numbers of that form:
399401
400402\begin {verbatim }
401- >>> 3./4 # utterly safe
402- 0.75
403+ >>> 3./4 # utterly safe
404+ 0.75
403405\end {verbatim }
404406
405407Simple fractions are also easier for people to understand, and that makes
0 commit comments