Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:4.4.2 SequenceMatcher ExamplesUp:4.4 difflibNext:4.4.4 Differ Example

 
4.4.3 Differ Objects

Note thatDiffer-generated deltas make no claim to beminimal diffs. To the contrary, minimal diffs are oftencounter-intuitive, because they synch up anywhere possible, sometimesaccidental matches 100 pages apart. Restricting synch points tocontiguous matches preserves some notion of locality, at theoccasional cost of producing a longer diff.

TheDiffer class has this constructor:

classDiffer([linejunk[, charjunk]])
Optional keyword parameterslinejunk andcharjunk are for filter functions (orNone):

linejunk: A function that should accept a single string argument, and return true if the string is junk. The default is module-level functionIS_LINE_JUNK(), which filters out lines without visible characters, except for at most one pound character ("#").

charjunk: A function that should accept a string of length 1. The default is module-level functionIS_CHARACTER_JUNK(), which filters out whitespace characters (a blank or tab; note: bad idea to include newline in this!).

Differ objects are used (deltas generated) via a singlemethod:

compare(a, b)
Compare two sequences of lines, and generate the delta (a sequence of lines).

Each sequence must contain individual single-line strings ending with newlines. Such sequences can be obtained from thereadlines() method of file-like objects. The delta generated also consists of newline-terminated strings, ready to be printed as-is via thewritelines() method of a file-like object.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:4.4.2 SequenceMatcher ExamplesUp:4.4 difflibNext:4.4.4 Differ Example
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp