Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: Doc/library/difflib.rst

Issue 18758: Fix internal references in the documentation
Patch Set: Created 6 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/dbm.rst ('k') | Doc/library/enum.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`difflib` --- Helpers for computing deltas 1 :mod:`difflib` --- Helpers for computing deltas
2 =============================================== 2 ===============================================
3 3
4 .. module:: difflib 4 .. module:: difflib
5 :synopsis: Helpers for computing differences between objects. 5 :synopsis: Helpers for computing differences between objects.
6 .. moduleauthor:: Tim Peters <tim_one@users.sourceforge.net> 6 .. moduleauthor:: Tim Peters <tim_one@users.sourceforge.net>
7 .. sectionauthor:: Tim Peters <tim_one@users.sourceforge.net> 7 .. sectionauthor:: Tim Peters <tim_one@users.sourceforge.net>
8 .. Markup by Fred L. Drake, Jr. <fdrake@acm.org> 8 .. Markup by Fred L. Drake, Jr. <fdrake@acm.org>
9 9
10 .. testsetup:: 10 .. testsetup::
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 Compare *a* and *b* (lists of strings); return a delta (a :term:`generator` 137 Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
138 generating the delta lines) in context diff format. 138 generating the delta lines) in context diff format.
139 139
140 Context diffs are a compact way of showing just the lines that have changed p lus 140 Context diffs are a compact way of showing just the lines that have changed p lus
141 a few lines of context. The changes are shown in a before/after style. The 141 a few lines of context. The changes are shown in a before/after style. The
142 number of context lines is set by *n* which defaults to three. 142 number of context lines is set by *n* which defaults to three.
143 143
144 By default, the diff control lines (those with ``***`` or ``---``) are create d 144 By default, the diff control lines (those with ``***`` or ``---``) are create d
145 with a trailing newline. This is helpful so that inputs created from 145 with a trailing newline. This is helpful so that inputs created from
146 :func:`file.readlines` result in diffs that are suitable for use with 146 :func:`io.IOBase.readlines` result in diffs that are suitable for use with
147 :func:`file.writelines` since both the inputs and outputs have trailing 147 :func:`io.IOBase.writelines` since both the inputs and outputs have trailing
148 newlines. 148 newlines.
149 149
150 For inputs that do not have trailing newlines, set the *lineterm* argument to 150 For inputs that do not have trailing newlines, set the *lineterm* argument to
151 ``""`` so that the output will be uniformly newline free. 151 ``""`` so that the output will be uniformly newline free.
152 152
153 The context diff format normally has a header for filenames and modification 153 The context diff format normally has a header for filenames and modification
154 times. Any or all of these may be specified using strings for *fromfile*, 154 times. Any or all of these may be specified using strings for *fromfile*,
155 *tofile*, *fromfiledate*, and *tofiledate*. The modification times are norma lly 155 *tofile*, *fromfiledate*, and *tofiledate*. The modification times are norma lly
156 expressed in the ISO 8601 format. If not specified, the 156 expressed in the ISO 8601 format. If not specified, the
157 strings default to blanks. 157 strings default to blanks.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 Compare *a* and *b* (lists of strings); return a delta (a :term:`generator` 268 Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
269 generating the delta lines) in unified diff format. 269 generating the delta lines) in unified diff format.
270 270
271 Unified diffs are a compact way of showing just the lines that have changed p lus 271 Unified diffs are a compact way of showing just the lines that have changed p lus
272 a few lines of context. The changes are shown in a inline style (instead of 272 a few lines of context. The changes are shown in a inline style (instead of
273 separate before/after blocks). The number of context lines is set by *n* whi ch 273 separate before/after blocks). The number of context lines is set by *n* whi ch
274 defaults to three. 274 defaults to three.
275 275
276 By default, the diff control lines (those with ``---``, ``+++``, or ``@@``) a re 276 By default, the diff control lines (those with ``---``, ``+++``, or ``@@``) a re
277 created with a trailing newline. This is helpful so that inputs created from 277 created with a trailing newline. This is helpful so that inputs created from
278 :func:`file.readlines` result in diffs that are suitable for use with 278 :func:`io.IOBase.readlines` result in diffs that are suitable for use with
279 :func:`file.writelines` since both the inputs and outputs have trailing 279 :func:`io.IOBase.writelines` since both the inputs and outputs have trailing
280 newlines. 280 newlines.
281 281
282 For inputs that do not have trailing newlines, set the *lineterm* argument to 282 For inputs that do not have trailing newlines, set the *lineterm* argument to
283 ``""`` so that the output will be uniformly newline free. 283 ``""`` so that the output will be uniformly newline free.
284 284
285 The context diff format normally has a header for filenames and modification 285 The context diff format normally has a header for filenames and modification
286 times. Any or all of these may be specified using strings for *fromfile*, 286 times. Any or all of these may be specified using strings for *fromfile*,
287 *tofile*, *fromfiledate*, and *tofiledate*. The modification times are norma lly 287 *tofile*, *fromfiledate*, and *tofiledate*. The modification times are norma lly
288 expressed in the ISO 8601 format. If not specified, the 288 expressed in the ISO 8601 format. If not specified, the
289 strings default to blanks. 289 strings default to blanks.
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 meaning that no character is considered junk. 623 meaning that no character is considered junk.
624 624
625 :class:`Differ` objects are used (deltas generated) via a single method: 625 :class:`Differ` objects are used (deltas generated) via a single method:
626 626
627 627
628 .. method:: Differ.compare(a, b) 628 .. method:: Differ.compare(a, b)
629 629
630 Compare two sequences of lines, and generate the delta (a sequence of line s). 630 Compare two sequences of lines, and generate the delta (a sequence of line s).
631 631
632 Each sequence must contain individual single-line strings ending with newl ines. 632 Each sequence must contain individual single-line strings ending with newl ines.
633 Such sequences can be obtained from the :meth:`readlines` method of file-l ike 633 Such sequences can be obtained from the :meth:`~io.IOBase.readlines` metho d of file-like
634 objects. The delta generated also consists of newline-terminated strings, ready 634 objects. The delta generated also consists of newline-terminated strings, ready
635 to be printed as-is via the :meth:`writelines` method of a file-like objec t. 635 to be printed as-is via the :meth:`~io.IOBase.writelines` method of a file -like object.
636 636
637 637
638 .. _differ-examples: 638 .. _differ-examples:
639 639
640 Differ Example 640 Differ Example
641 -------------- 641 --------------
642 642
643 This example compares two texts. First we set up the texts, sequences of 643 This example compares two texts. First we set up the texts, sequences of
644 individual single-line strings ending with newlines (such sequences can also be 644 individual single-line strings ending with newlines (such sequences can also be
645 obtained from the :meth:`readlines` method of file-like objects): 645 obtained from the :meth:`~io.BaseIO.readlines` method of file-like objects):
646 646
647 >>> text1 = ''' 1. Beautiful is better than ugly. 647 >>> text1 = ''' 1. Beautiful is better than ugly.
648 ... 2. Explicit is better than implicit. 648 ... 2. Explicit is better than implicit.
649 ... 3. Simple is better than complex. 649 ... 3. Simple is better than complex.
650 ... 4. Complex is better than complicated. 650 ... 4. Complex is better than complicated.
651 ... '''.splitlines(1) 651 ... '''.splitlines(1)
652 >>> len(text1) 652 >>> len(text1)
653 4 653 4
654 >>> text1[0][-1] 654 >>> text1[0][-1]
655 '\n' 655 '\n'
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 numlines=n) 766 numlines=n)
767 else: 767 else:
768 diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, 768 diff = difflib.context_diff(fromlines, tolines, fromfile, tofile,
769 fromdate, todate, n=n) 769 fromdate, todate, n=n)
770 770
771 # we're using writelines because diff is a generator 771 # we're using writelines because diff is a generator
772 sys.stdout.writelines(diff) 772 sys.stdout.writelines(diff)
773 773
774 if __name__ == '__main__': 774 if __name__ == '__main__':
775 main() 775 main()
OLDNEW
« no previous file with comments | « Doc/library/dbm.rst ('k') | Doc/library/enum.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+