How do I use python

I recently installed python-WikEdDiff package to my system. I understand it is a python extension of the original JavaScript WikEdDiff tool. I tried to use it but I couldn't find any documentation for it. I am stuck at using WikEdDiff.diff() . I wish to use the other functions of this class, such as getFragments() and others, but on checking, it shows the following error:

 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

On checking, I found out that the tokens[] structure in the object remains empty whereas it should have been initialized.

Is there an initialize function that I need to call apart from the default constructor? Or is it something to do with the `WikEdDiffConfig' config structure I passed to the constructor?


You get this error because the WikEdDiff object was cleared internally inside diff() , as shown in this section of the code:

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

If you just need the fragments, use the returned variable of diff() like this:

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+ ] }'
链接地址: http://www.djcxy.com/p/30320.html

上一篇: 划定特定列并将它们添加为CSV(Python3,CSV)列

下一篇: 我如何使用python