我如何使用python-WikEdDiff?

Aay*_*Dee 7 python diff package

我最近安装了python-WikEdDiff包到我的系统.我知道它是原始JavaScript WikEdDiff工具的python扩展.我试图使用它,但我找不到任何文档.我坚持使用WikEdDiff.diff().我希望使用此类的其他函数,例如getFragments()和其他函数,但在检查时,它显示以下错误:

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/WikEdDiff/diff.py", line 1123, in detectBlocks
    self.getSameBlocks()
  File "/usr/local/lib/python3.4/dist-packages/WikEdDiff/diff.py", line 1211, in getSameBlocks
    while j is not None and self.oldText.tokens[j].link is None:
IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)

在检查时,我发现tokens[]对象中的结构保持为空,而它应该已经初始化.

是否有一个初始化函数,我需要调用默认构造函数?或者它是否与我传递给构造函数的`WikEdDiffConfig'配置结构有关?

gdl*_*lmx 3

您收到此错误是因为该WikEdDiff对象在内部被清除,如这部分代码diff()所示:

def diff( self, oldString, newString ):
    ...
    # Free memory
    self.newText.tokens.clear()
    self.oldText.tokens.clear()
    # Assemble blocks into fragment table
    fragments = self.getDiffFragments()
    # Free memory
    self.blocks.clear()
    self.groups.clear()
    self.sections.clear()
    ...
    return fragments
Run Code Online (Sandbox Code Playgroud)

如果您只需要片段,请使用返回的变量,diff()如下所示:

import WikEdDiff as WED
config=WED.WikEdDiffConfig()
w = WED.WikEdDiff(config)
f = w.diff("abc", "efg")
# do whatever you want with f, but don't use w
print(' '.join([i.text+i.type for i in f]))
# outputs '{ [ (> abc-  ) abc< efg+ ] }'
Run Code Online (Sandbox Code Playgroud)