{
    "mode": "pydoc",
    "parameter": "difflib",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/difflib/json",
    "generated": "2026-11-20T07:54:15Z",
    "sections": {
        "NAME": {
            "content": "difflib - Module difflib -- helpers for computing deltas between objects.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.12/library/difflib.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Function getclosematches(word, possibilities, n=3, cutoff=0.6):\nUse SequenceMatcher to return list of the best \"good enough\" matches.\n\nFunction contextdiff(a, b):\nFor two lists of strings, return a delta in context diff format.\n\nFunction ndiff(a, b):\nReturn a delta: the difference between `a` and `b` (lists of strings).\n\nFunction restore(delta, which):\nReturn one of the two sequences that generated an ndiff delta.\n\nFunction unifieddiff(a, b):\nFor two lists of strings, return a delta in unified diff format.\n\nClass SequenceMatcher:\nA flexible class for comparing pairs of sequences of any type.\n\nClass Differ:\nFor producing human-readable deltas from sequences of lines of text.\n\nClass HtmlDiff:\nFor producing HTML side by side comparison with change highlights.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.object\nDiffer\nHtmlDiff\nSequenceMatcher\nbuiltins.tuple(builtins.object)\nMatch\n",
            "subsections": [
                {
                    "name": "class Differ",
                    "content": "|  Differ(linejunk=None, charjunk=None)\n|\n|  Differ is a class for comparing sequences of lines of text, and\n|  producing human-readable differences or deltas.  Differ uses\n|  SequenceMatcher both to compare sequences of lines, and to compare\n|  sequences of characters within similar (near-matching) lines.\n|\n|  Each line of a Differ delta begins with a two-letter code:\n|\n|      '- '    line unique to sequence 1\n|      '+ '    line unique to sequence 2\n|      '  '    line common to both sequences\n|      '? '    line not present in either input sequence\n|\n|  Lines beginning with '? ' attempt to guide the eye to intraline\n|  differences, and were not present in either input sequence.  These lines\n|  can be confusing if the sequences contain tab characters.\n|\n|  Note that Differ makes no claim to produce a *minimal* diff.  To the\n|  contrary, minimal diffs are often counter-intuitive, because they synch\n|  up anywhere possible, sometimes accidental matches 100 pages apart.\n|  Restricting synch points to contiguous matches preserves some notion of\n|  locality, at the occasional cost of producing a longer diff.\n|\n|  Example: Comparing two texts.\n|\n|  First we set up the texts, sequences of individual single-line strings\n|  ending with newlines (such sequences can also be obtained from the\n|  `readlines()` method of file-like objects):\n|\n|  >>> text1 = '''  1. Beautiful is better than ugly.\n|  ...   2. Explicit is better than implicit.\n|  ...   3. Simple is better than complex.\n|  ...   4. Complex is better than complicated.\n|  ... '''.splitlines(keepends=True)\n|  >>> len(text1)\n|  4\n|  >>> text1[0][-1]\n|  '\\n'\n|  >>> text2 = '''  1. Beautiful is better than ugly.\n|  ...   3.   Simple is better than complex.\n|  ...   4. Complicated is better than complex.\n|  ...   5. Flat is better than nested.\n|  ... '''.splitlines(keepends=True)\n|\n|  Next we instantiate a Differ object:\n|\n|  >>> d = Differ()\n|\n|  Note that when instantiating a Differ object we may pass functions to\n|  filter out line and character 'junk'.  See Differ.init for details.\n|\n|  Finally, we compare the two:\n|\n|  >>> result = list(d.compare(text1, text2))\n|\n|  'result' is a list of strings, so let's pretty-print it:\n|\n|  >>> from pprint import pprint as pprint\n|  >>> pprint(result)\n|  ['    1. Beautiful is better than ugly.\\n',\n|   '-   2. Explicit is better than implicit.\\n',\n|   '-   3. Simple is better than complex.\\n',\n|   '+   3.   Simple is better than complex.\\n',\n|   '?     ++\\n',\n|   '-   4. Complex is better than complicated.\\n',\n|   '?            ^                     ---- ^\\n',\n|   '+   4. Complicated is better than complex.\\n',\n|   '?           ++++ ^                      ^\\n',\n|   '+   5. Flat is better than nested.\\n']\n|\n|  As a single multi-line string it looks like this:\n|\n|  >>> print(''.join(result), end=\"\")\n|      1. Beautiful is better than ugly.\n|  -   2. Explicit is better than implicit.\n|  -   3. Simple is better than complex.\n|  +   3.   Simple is better than complex.\n|  ?     ++\n|  -   4. Complex is better than complicated.\n|  ?            ^                     ---- ^\n|  +   4. Complicated is better than complex.\n|  ?           ++++ ^                      ^\n|  +   5. Flat is better than nested.\n|\n|  Methods defined here:\n|\n|  init(self, linejunk=None, charjunk=None)\n|      Construct a text differencer, with optional filters.\n|\n|      The two optional keyword parameters are for filter functions:\n|\n|      - `linejunk`: A function that should accept a single string argument,\n|        and return true iff the string is junk. The module-level function\n|        `ISLINEJUNK` may be used to filter out lines without visible\n|        characters, except for at most one splat ('#').  It is recommended\n|        to leave linejunk None; the underlying SequenceMatcher class has\n|        an adaptive notion of \"noise\" lines that's better than any static\n|        definition the author has ever been able to craft.\n|\n|      - `charjunk`: A function that should accept a string of length 1. The\n|        module-level function `ISCHARACTERJUNK` may be used to filter out\n|        whitespace characters (a blank or tab; note: bad idea to include\n|        newline in this!).  Use of ISCHARACTERJUNK is recommended.\n|\n|  compare(self, a, b)\n|      Compare two sequences of lines; generate the resulting delta.\n|\n|      Each sequence must contain individual single-line strings ending with\n|      newlines. Such sequences can be obtained from the `readlines()` method\n|      of file-like objects.  The delta generated also consists of newline-\n|      terminated strings, ready to be printed as-is via the writelines()\n|      method of a file-like object.\n|\n|      Example:\n|\n|      >>> print(''.join(Differ().compare('one\\ntwo\\nthree\\n'.splitlines(True),\n|      ...                                'ore\\ntree\\nemu\\n'.splitlines(True))),\n|      ...       end=\"\")\n|      - one\n|      ?  ^\n|      + ore\n|      ?  ^\n|      - two\n|      - three\n|      ?  -\n|      + tree\n|      + emu\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables\n|\n|  weakref\n|      list of weak references to the object\n"
                },
                {
                    "name": "class HtmlDiff",
                    "content": "|  HtmlDiff(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=<function ISCHARACTERJUNK at 0x7f3b9dea3920>)\n|\n|  For producing HTML side by side comparison with change highlights.\n|\n|  This class can be used to create an HTML table (or a complete HTML file\n|  containing the table) showing a side by side, line by line comparison\n|  of text with inter-line and intra-line change highlights.  The table can\n|  be generated in either full or contextual difference mode.\n|\n|  The following methods are provided for HTML generation:\n|\n|  maketable -- generates HTML for a single side by side table\n|  makefile -- generates complete HTML file with a single side by side table\n|\n|  See tools/scripts/diff.py for an example usage of this class.\n|\n|  Methods defined here:\n|\n|  init(self, tabsize=8, wrapcolumn=None, linejunk=None, charjunk=<function ISCHARACTERJUNK at 0x7f3b9dea3920>)\n|      HtmlDiff instance initializer\n|\n|      Arguments:\n|      tabsize -- tab stop spacing, defaults to 8.\n|      wrapcolumn -- column number where lines are broken and wrapped,\n|          defaults to None where lines are not wrapped.\n|      linejunk,charjunk -- keyword arguments passed into ndiff() (used by\n|          HtmlDiff() to generate the side by side HTML differences).  See\n|          ndiff() documentation for argument default values and descriptions.\n|\n|  makefile(self, fromlines, tolines, fromdesc='', todesc='', context=False, numlines=5, *, charset='utf-8')\n|      Returns HTML file of side by side comparison with change highlights\n|\n|      Arguments:\n|      fromlines -- list of \"from\" lines\n|      tolines -- list of \"to\" lines\n|      fromdesc -- \"from\" file column header string\n|      todesc -- \"to\" file column header string\n|      context -- set to True for contextual differences (defaults to False\n|          which shows full differences).\n|      numlines -- number of context lines.  When context is set True,\n|          controls number of lines displayed before and after the change.\n|          When context is False, controls the number of lines to place\n|          the \"next\" link anchors before the next change (so click of\n|          \"next\" link jumps to just before the change).\n|      charset -- charset of the HTML document\n|\n|  maketable(self, fromlines, tolines, fromdesc='', todesc='', context=False, numlines=5)\n|      Returns HTML table of side by side comparison with change highlights\n|\n|      Arguments:\n|      fromlines -- list of \"from\" lines\n|      tolines -- list of \"to\" lines\n|      fromdesc -- \"from\" file column header string\n|      todesc -- \"to\" file column header string\n|      context -- set to True for contextual differences (defaults to False\n|          which shows full differences).\n|      numlines -- number of context lines.  When context is set True,\n|          controls number of lines displayed before and after the change.\n|          When context is False, controls the number of lines to place\n|          the \"next\" link anchors before the next change (so click of\n|          \"next\" link jumps to just before the change).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables\n|\n|  weakref\n|      list of weak references to the object\n"
                },
                {
                    "name": "class Match",
                    "content": "|  Match(a, b, size)\n|\n|  Match(a, b, size)\n|\n|  Method resolution order:\n|      Match\n|      builtins.tuple\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  getnewargs(self) from collections.Match\n|      Return self as a plain tuple.  Used by copy and pickle.\n|\n|  repr(self) from collections.Match\n|      Return a nicely formatted representation string\n|\n|  asdict(self) from collections.Match\n|      Return a new dict which maps field names to their values.\n|\n|  replace(self, /, kwds) from collections.Match\n|      Return a new Match object replacing specified fields with new values\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  make(iterable) from collections.Match\n|      Make a new Match object from a sequence or iterable\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(cls, a, b, size) from namedtupleMatch.Match\n|      Create new instance of Match(a, b, size)\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  a\n|      Alias for field number 0\n|\n|  b\n|      Alias for field number 1\n|\n|  size\n|      Alias for field number 2\n|\n|  ----------------------------------------------------------------------\n|  Data and other attributes defined here:\n|\n|  matchargs = ('a', 'b', 'size')\n|\n|  fielddefaults = {}\n|\n|  fields = ('a', 'b', 'size')\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.tuple:\n|\n|  add(self, value, /)\n|      Return self+value.\n|\n|  contains(self, key, /)\n|      Return bool(key in self).\n|\n|  eq(self, value, /)\n|      Return self==value.\n|\n|  ge(self, value, /)\n|      Return self>=value.\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  getitem(self, key, /)\n|      Return self[key].\n|\n|  gt(self, value, /)\n|      Return self>value.\n|\n|  hash(self, /)\n|      Return hash(self).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  le(self, value, /)\n|      Return self<=value.\n|\n|  len(self, /)\n|      Return len(self).\n|\n|  lt(self, value, /)\n|      Return self<value.\n|\n|  mul(self, value, /)\n|      Return self*value.\n|\n|  ne(self, value, /)\n|      Return self!=value.\n|\n|  rmul(self, value, /)\n|      Return value*self.\n|\n|  count(self, value, /)\n|      Return number of occurrences of value.\n|\n|  index(self, value, start=0, stop=9223372036854775807, /)\n|      Return first index of value.\n|\n|      Raises ValueError if the value is not present.\n|\n|  ----------------------------------------------------------------------\n|  Class methods inherited from builtins.tuple:\n|\n|  classgetitem(...)\n|      See PEP 585\n"
                },
                {
                    "name": "class SequenceMatcher",
                    "content": "|  SequenceMatcher(isjunk=None, a='', b='', autojunk=True)\n|\n|  SequenceMatcher is a flexible class for comparing pairs of sequences of\n|  any type, so long as the sequence elements are hashable.  The basic\n|  algorithm predates, and is a little fancier than, an algorithm\n|  published in the late 1980's by Ratcliff and Obershelp under the\n|  hyperbolic name \"gestalt pattern matching\".  The basic idea is to find\n|  the longest contiguous matching subsequence that contains no \"junk\"\n|  elements (R-O doesn't address junk).  The same idea is then applied\n|  recursively to the pieces of the sequences to the left and to the right\n|  of the matching subsequence.  This does not yield minimal edit\n|  sequences, but does tend to yield matches that \"look right\" to people.\n|\n|  SequenceMatcher tries to compute a \"human-friendly diff\" between two\n|  sequences.  Unlike e.g. UNIX(tm) diff, the fundamental notion is the\n|  longest *contiguous* & junk-free matching subsequence.  That's what\n|  catches peoples' eyes.  The Windows(tm) windiff has another interesting\n|  notion, pairing up elements that appear uniquely in each sequence.\n|  That, and the method here, appear to yield more intuitive difference\n|  reports than does diff.  This method appears to be the least vulnerable\n|  to syncing up on blocks of \"junk lines\", though (like blank lines in\n|  ordinary text files, or maybe \"<P>\" lines in HTML files).  That may be\n|  because this is the only method of the 3 that has a *concept* of\n|  \"junk\" <wink>.\n|\n|  Example, comparing two strings, and considering blanks to be \"junk\":\n|\n|  >>> s = SequenceMatcher(lambda x: x == \" \",\n|  ...                     \"private Thread currentThread;\",\n|  ...                     \"private volatile Thread currentThread;\")\n|  >>>\n|\n|  .ratio() returns a float in [0, 1], measuring the \"similarity\" of the\n|  sequences.  As a rule of thumb, a .ratio() value over 0.6 means the\n|  sequences are close matches:\n|\n|  >>> print(round(s.ratio(), 3))\n|  0.866\n|  >>>\n|\n|  If you're only interested in where the sequences match,\n|  .getmatchingblocks() is handy:\n|\n|  >>> for block in s.getmatchingblocks():\n|  ...     print(\"a[%d] and b[%d] match for %d elements\" % block)\n|  a[0] and b[0] match for 8 elements\n|  a[8] and b[17] match for 21 elements\n|  a[29] and b[38] match for 0 elements\n|\n|  Note that the last tuple returned by .getmatchingblocks() is always a\n|  dummy, (len(a), len(b), 0), and this is the only case in which the last\n|  tuple element (number of elements matched) is 0.\n|\n|  If you want to know how to change the first sequence into the second,\n|  use .getopcodes():\n|\n|  >>> for opcode in s.getopcodes():\n|  ...     print(\"%6s a[%d:%d] b[%d:%d]\" % opcode)\n|   equal a[0:8] b[0:8]\n|  insert a[8:8] b[8:17]\n|   equal a[8:29] b[17:38]\n|\n|  See the Differ class for a fancy human-friendly file differencer, which\n|  uses SequenceMatcher both to compare sequences of lines, and to compare\n|  sequences of characters within similar (near-matching) lines.\n|\n|  See also function getclosematches() in this module, which shows how\n|  simple code building on SequenceMatcher can be used to do useful work.\n|\n|  Timing:  Basic R-O is cubic time worst case and quadratic time expected\n|  case.  SequenceMatcher is quadratic time for the worst case and has\n|  expected-case behavior dependent in a complicated way on how many\n|  elements the sequences have in common; best case time is linear.\n|\n|  Methods defined here:\n|\n|  init(self, isjunk=None, a='', b='', autojunk=True)\n|      Construct a SequenceMatcher.\n|\n|      Optional arg isjunk is None (the default), or a one-argument\n|      function that takes a sequence element and returns true iff the\n|      element is junk.  None is equivalent to passing \"lambda x: 0\", i.e.\n|      no elements are considered to be junk.  For example, pass\n|          lambda x: x in \" \\t\"\n|      if you're comparing lines as sequences of characters, and don't\n|      want to synch up on blanks or hard tabs.\n|\n|      Optional arg a is the first of two sequences to be compared.  By\n|      default, an empty string.  The elements of a must be hashable.  See\n|      also .setseqs() and .setseq1().\n|\n|      Optional arg b is the second of two sequences to be compared.  By\n|      default, an empty string.  The elements of b must be hashable. See\n|      also .setseqs() and .setseq2().\n|\n|      Optional arg autojunk should be set to False to disable the\n|      \"automatic junk heuristic\" that treats popular elements as junk\n|      (see module documentation for more information).\n|\n|  findlongestmatch(self, alo=0, ahi=None, blo=0, bhi=None)\n|      Find longest matching block in a[alo:ahi] and b[blo:bhi].\n|\n|      By default it will find the longest match in the entirety of a and b.\n|\n|      If isjunk is not defined:\n|\n|      Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where\n|          alo <= i <= i+k <= ahi\n|          blo <= j <= j+k <= bhi\n|      and for all (i',j',k') meeting those conditions,\n|          k >= k'\n|          i <= i'\n|          and if i == i', j <= j'\n|\n|      In other words, of all maximal matching blocks, return one that\n|      starts earliest in a, and of all those maximal matching blocks that\n|      start earliest in a, return the one that starts earliest in b.\n|\n|      >>> s = SequenceMatcher(None, \" abcd\", \"abcd abcd\")\n|      >>> s.findlongestmatch(0, 5, 0, 9)\n|      Match(a=0, b=4, size=5)\n|\n|      If isjunk is defined, first the longest matching block is\n|      determined as above, but with the additional restriction that no\n|      junk element appears in the block.  Then that block is extended as\n|      far as possible by matching (only) junk elements on both sides.  So\n|      the resulting block never matches on junk except as identical junk\n|      happens to be adjacent to an \"interesting\" match.\n|\n|      Here's the same example as before, but considering blanks to be\n|      junk.  That prevents \" abcd\" from matching the \" abcd\" at the tail\n|      end of the second sequence directly.  Instead only the \"abcd\" can\n|      match, and matches the leftmost \"abcd\" in the second sequence:\n|\n|      >>> s = SequenceMatcher(lambda x: x==\" \", \" abcd\", \"abcd abcd\")\n|      >>> s.findlongestmatch(0, 5, 0, 9)\n|      Match(a=1, b=0, size=4)\n|\n|      If no blocks match, return (alo, blo, 0).\n|\n|      >>> s = SequenceMatcher(None, \"ab\", \"c\")\n|      >>> s.findlongestmatch(0, 2, 0, 1)\n|      Match(a=0, b=0, size=0)\n|\n|  getgroupedopcodes(self, n=3)\n|      Isolate change clusters by eliminating ranges with no changes.\n|\n|      Return a generator of groups with up to n lines of context.\n|      Each group is in the same format as returned by getopcodes().\n|\n|      >>> from pprint import pprint\n|      >>> a = list(map(str, range(1,40)))\n|      >>> b = a[:]\n|      >>> b[8:8] = ['i']     # Make an insertion\n|      >>> b[20] += 'x'       # Make a replacement\n|      >>> b[23:28] = []      # Make a deletion\n|      >>> b[30] += 'y'       # Make another replacement\n|      >>> pprint(list(SequenceMatcher(None,a,b).getgroupedopcodes()))\n|      [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],\n|       [('equal', 16, 19, 17, 20),\n|        ('replace', 19, 20, 20, 21),\n|        ('equal', 20, 22, 21, 23),\n|        ('delete', 22, 27, 23, 23),\n|        ('equal', 27, 30, 23, 26)],\n|       [('equal', 31, 34, 27, 30),\n|        ('replace', 34, 35, 30, 31),\n|        ('equal', 35, 38, 31, 34)]]\n|\n|  getmatchingblocks(self)\n|      Return list of triples describing matching subsequences.\n|\n|      Each triple is of the form (i, j, n), and means that\n|      a[i:i+n] == b[j:j+n].  The triples are monotonically increasing in\n|      i and in j.  New in Python 2.5, it's also guaranteed that if\n|      (i, j, n) and (i', j', n') are adjacent triples in the list, and\n|      the second is not the last triple in the list, then i+n != i' or\n|      j+n != j'.  IOW, adjacent triples never describe adjacent equal\n|      blocks.\n|\n|      The last triple is a dummy, (len(a), len(b), 0), and is the only\n|      triple with n==0.\n|\n|      >>> s = SequenceMatcher(None, \"abxcd\", \"abcd\")\n|      >>> list(s.getmatchingblocks())\n|      [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]\n|\n|  getopcodes(self)\n|      Return list of 5-tuples describing how to turn a into b.\n|\n|      Each tuple is of the form (tag, i1, i2, j1, j2).  The first tuple\n|      has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the\n|      tuple preceding it, and likewise for j1 == the previous j2.\n|\n|      The tags are strings, with these meanings:\n|\n|      'replace':  a[i1:i2] should be replaced by b[j1:j2]\n|      'delete':   a[i1:i2] should be deleted.\n|                  Note that j1==j2 in this case.\n|      'insert':   b[j1:j2] should be inserted at a[i1:i1].\n|                  Note that i1==i2 in this case.\n|      'equal':    a[i1:i2] == b[j1:j2]\n|\n|      >>> a = \"qabxcd\"\n|      >>> b = \"abycdf\"\n|      >>> s = SequenceMatcher(None, a, b)\n|      >>> for tag, i1, i2, j1, j2 in s.getopcodes():\n|      ...    print((\"%7s a[%d:%d] (%s) b[%d:%d] (%s)\" %\n|      ...           (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))\n|       delete a[0:1] (q) b[0:0] ()\n|        equal a[1:3] (ab) b[0:2] (ab)\n|      replace a[3:4] (x) b[2:3] (y)\n|        equal a[4:6] (cd) b[3:5] (cd)\n|       insert a[6:6] () b[5:6] (f)\n|\n|  quickratio(self)\n|      Return an upper bound on ratio() relatively quickly.\n|\n|      This isn't defined beyond that it is an upper bound on .ratio(), and\n|      is faster to compute.\n|\n|  ratio(self)\n|      Return a measure of the sequences' similarity (float in [0,1]).\n|\n|      Where T is the total number of elements in both sequences, and\n|      M is the number of matches, this is 2.0*M / T.\n|      Note that this is 1 if the sequences are identical, and 0 if\n|      they have nothing in common.\n|\n|      .ratio() is expensive to compute if you haven't already computed\n|      .getmatchingblocks() or .getopcodes(), in which case you may\n|      want to try .quickratio() or .realquickratio() first to get an\n|      upper bound.\n|\n|      >>> s = SequenceMatcher(None, \"abcd\", \"bcde\")\n|      >>> s.ratio()\n|      0.75\n|      >>> s.quickratio()\n|      0.75\n|      >>> s.realquickratio()\n|      1.0\n|\n|  realquickratio(self)\n|      Return an upper bound on ratio() very quickly.\n|\n|      This isn't defined beyond that it is an upper bound on .ratio(), and\n|      is faster to compute than either .ratio() or .quickratio().\n|\n|  setseq1(self, a)\n|      Set the first sequence to be compared.\n|\n|      The second sequence to be compared is not changed.\n|\n|      >>> s = SequenceMatcher(None, \"abcd\", \"bcde\")\n|      >>> s.ratio()\n|      0.75\n|      >>> s.setseq1(\"bcde\")\n|      >>> s.ratio()\n|      1.0\n|      >>>\n|\n|      SequenceMatcher computes and caches detailed information about the\n|      second sequence, so if you want to compare one sequence S against\n|      many sequences, use .setseq2(S) once and call .setseq1(x)\n|      repeatedly for each of the other sequences.\n|\n|      See also setseqs() and setseq2().\n|\n|  setseq2(self, b)\n|      Set the second sequence to be compared.\n|\n|      The first sequence to be compared is not changed.\n|\n|      >>> s = SequenceMatcher(None, \"abcd\", \"bcde\")\n|      >>> s.ratio()\n|      0.75\n|      >>> s.setseq2(\"abcd\")\n|      >>> s.ratio()\n|      1.0\n|      >>>\n|\n|      SequenceMatcher computes and caches detailed information about the\n|      second sequence, so if you want to compare one sequence S against\n|      many sequences, use .setseq2(S) once and call .setseq1(x)\n|      repeatedly for each of the other sequences.\n|\n|      See also setseqs() and setseq1().\n|\n|  setseqs(self, a, b)\n|      Set the two sequences to be compared.\n|\n|      >>> s = SequenceMatcher()\n|      >>> s.setseqs(\"abcd\", \"bcde\")\n|      >>> s.ratio()\n|      0.75\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  classgetitem = GenericAlias(...)\n|      Represent a PEP 585 generic type\n|\n|      E.g. for t = list[int], t.origin is list and t.args is (int,).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables\n|\n|  weakref\n|      list of weak references to the object\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "ISCHARACTERJUNK(ch, ws=' \\t')\nReturn True for ignorable character: iff `ch` is a space or tab.\n\nExamples:\n\n>>> ISCHARACTERJUNK(' ')\nTrue\n>>> ISCHARACTERJUNK('\\t')\nTrue\n>>> ISCHARACTERJUNK('\\n')\nFalse\n>>> ISCHARACTERJUNK('x')\nFalse\n\nISLINEJUNK(line, pat=<built-in method match of re.Pattern object at 0x7f3b9debc240>)\nReturn True for ignorable line: iff `line` is blank or contains a single '#'.\n\nExamples:\n\n>>> ISLINEJUNK('\\n')\nTrue\n>>> ISLINEJUNK('  #   \\n')\nTrue\n>>> ISLINEJUNK('hello\\n')\nFalse\n",
            "subsections": [
                {
                    "name": "context_diff",
                    "content": "Compare two sequences of lines; generate the delta as a context diff.\n\nContext diffs are a compact way of showing line changes and a few\nlines of context.  The number of context lines is set by 'n' which\ndefaults to three.\n\nBy default, the diff control lines (those with * or ---) are\ncreated with a trailing newline.  This is helpful so that inputs\ncreated from file.readlines() result in diffs that are suitable for\nfile.writelines() since both the inputs and outputs have trailing\nnewlines.\n\nFor inputs that do not have trailing newlines, set the lineterm\nargument to \"\" so that the output will be uniformly newline free.\n\nThe context diff format normally has a header for filenames and\nmodification times.  Any or all of these may be specified using\nstrings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.\nThe modification times are normally expressed in the ISO 8601 format.\nIf not specified, the strings default to blanks.\n\nExample:\n\n>>> print(''.join(contextdiff('one\\ntwo\\nthree\\nfour\\n'.splitlines(True),\n...       'zero\\none\\ntree\\nfour\\n'.splitlines(True), 'Original', 'Current')),\n...       end=\"\")\n* Original\n--- Current\n*\n* 1,4\none\n! two\n! three\nfour\n--- 1,4 ----\n+ zero\none\n! tree\nfour\n"
                },
                {
                    "name": "diff_bytes",
                    "content": "Compare `a` and `b`, two sequences of lines represented as bytes rather\nthan str. This is a wrapper for `dfunc`, which is typically either\nunifieddiff() or contextdiff(). Inputs are losslessly converted to\nstrings so that `dfunc` only has to worry about strings, and encoded\nback to bytes on return. This is necessary to compare files with\nunknown or inconsistent encoding. All other inputs (except `n`) must be\nbytes rather than str.\n"
                },
                {
                    "name": "get_close_matches",
                    "content": "Use SequenceMatcher to return list of the best \"good enough\" matches.\n\nword is a sequence for which close matches are desired (typically a\nstring).\n\npossibilities is a list of sequences against which to match word\n(typically a list of strings).\n\nOptional arg n (default 3) is the maximum number of close matches to\nreturn.  n must be > 0.\n\nOptional arg cutoff (default 0.6) is a float in [0, 1].  Possibilities\nthat don't score at least that similar to word are ignored.\n\nThe best (no more than n) matches among the possibilities are returned\nin a list, sorted by similarity score, most similar first.\n\n>>> getclosematches(\"appel\", [\"ape\", \"apple\", \"peach\", \"puppy\"])\n['apple', 'ape']\n>>> import keyword as keyword\n>>> getclosematches(\"wheel\", keyword.kwlist)\n['while']\n>>> getclosematches(\"Apple\", keyword.kwlist)\n[]\n>>> getclosematches(\"accept\", keyword.kwlist)\n['except']\n"
                },
                {
                    "name": "ndiff",
                    "content": "Compare `a` and `b` (lists of strings); return a `Differ`-style delta.\n\nOptional keyword parameters `linejunk` and `charjunk` are for filter\nfunctions, or can be None:\n\n- linejunk: A function that should accept a single string argument and\nreturn true iff the string is junk.  The default is None, and is\nrecommended; the underlying SequenceMatcher class has an adaptive\nnotion of \"noise\" lines.\n\n- charjunk: A function that accepts a character (string of length\n1), and returns true iff the character is junk. The default is\nthe module-level function ISCHARACTERJUNK, which filters out\nwhitespace characters (a blank or tab; note: it's a bad idea to\ninclude newline in this!).\n\nTools/scripts/ndiff.py is a command-line front-end to this function.\n\nExample:\n\n>>> diff = ndiff('one\\ntwo\\nthree\\n'.splitlines(keepends=True),\n...              'ore\\ntree\\nemu\\n'.splitlines(keepends=True))\n>>> print(''.join(diff), end=\"\")\n- one\n?  ^\n+ ore\n?  ^\n- two\n- three\n?  -\n+ tree\n+ emu\n"
                },
                {
                    "name": "restore",
                    "content": "Generate one of the two sequences that generated a delta.\n\nGiven a `delta` produced by `Differ.compare()` or `ndiff()`, extract\nlines originating from file 1 or 2 (parameter `which`), stripping off line\nprefixes.\n\nExamples:\n\n>>> diff = ndiff('one\\ntwo\\nthree\\n'.splitlines(keepends=True),\n...              'ore\\ntree\\nemu\\n'.splitlines(keepends=True))\n>>> diff = list(diff)\n>>> print(''.join(restore(diff, 1)), end=\"\")\none\ntwo\nthree\n>>> print(''.join(restore(diff, 2)), end=\"\")\nore\ntree\nemu\n"
                },
                {
                    "name": "unified_diff",
                    "content": "Compare two sequences of lines; generate the delta as a unified diff.\n\nUnified diffs are a compact way of showing line changes and a few\nlines of context.  The number of context lines is set by 'n' which\ndefaults to three.\n\nBy default, the diff control lines (those with ---, +++, or @@) are\ncreated with a trailing newline.  This is helpful so that inputs\ncreated from file.readlines() result in diffs that are suitable for\nfile.writelines() since both the inputs and outputs have trailing\nnewlines.\n\nFor inputs that do not have trailing newlines, set the lineterm\nargument to \"\" so that the output will be uniformly newline free.\n\nThe unidiff format normally has a header for filenames and modification\ntimes.  Any or all of these may be specified using strings for\n'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.\nThe modification times are normally expressed in the ISO 8601 format.\n\nExample:\n\n>>> for line in unifieddiff('one two three four'.split(),\n...             'zero one tree four'.split(), 'Original', 'Current',\n...             '2005-01-26 23:30:50', '2010-04-02 10:20:52',\n...             lineterm=''):\n...     print(line)                 # doctest: +NORMALIZEWHITESPACE\n--- Original        2005-01-26 23:30:50\n+++ Current         2010-04-02 10:20:52\n@@ -1,4 +1,4 @@\n+zero\none"
                },
                {
                    "name": "-two",
                    "content": ""
                },
                {
                    "name": "-three",
                    "content": "+tree\nfour\n"
                }
            ]
        },
        "DATA": {
            "content": "all = ['getclosematches', 'ndiff', 'restore', 'SequenceMatcher',...\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.12/difflib.py\n\n",
            "subsections": []
        }
    },
    "summary": "difflib - Module difflib -- helpers for computing deltas between objects.",
    "flags": [],
    "examples": [],
    "see_also": []
}