當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python difflib.restore用法及代碼示例


用法:

difflib.restore(sequence, which)

返回生成增量的兩個序列之一。

給定由 Differ.compare()ndiff() 生成的 sequence,提取源自文件 1 或 2(參數 which )的行,去除行前綴。

例子:

>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
...              'ore\ntree\nemu\n'.splitlines(keepends=True))
>>> diff = list(diff) # materialize the generated delta into a list
>>> print(''.join(restore(diff, 1)), end="")
one
two
three
>>> print(''.join(restore(diff, 2)), end="")
ore
tree
emu

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 difflib.restore。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。