DiffLib Question

whitewave fruels at gmail.com
Wed May 2 04:46:17 EDT 2007


Hi Guys,
    I'm a bit confused in difflib. In most cases, the differences
found  using difflib works well but when I have come across the
following set of text:

>>> d1 = '''In addition, the considered problem does not have a meaningful traditional type of adjoint
... problem even for the simple forms of the differential equation and
the nonlocal conditions. Due to these facts, some serious difficulties
arise in the application of the classical methods to such a
problem.'''
>>> d2 = '''In addition, the considered problem does not have a meaningful traditional type of
... adjoint problem even for the simple forms of the differential
equation and the nonlocal conditions. Due
... to these facts, some serious difficulties arise in the application
of the classical methods to such a
... problem. '''

Using this line of code:

>>> a = difflib.Differ().compare(d1,d2)
>>> dif =[]
>>> for i in a:
...     dif.append(i)
...     s = ''.join(dif)

I get the following output:

'  I  n     a  d  d  i  t  i  o  n  ,     t  h  e     c  o  n  s  i
d  e  r  e  d     p  r  o  b  l  e  m     d  o  e  s     n  o  t
h  a  v  e     a     m  e  a  n  i  n  g  f  u  l     t  r  a  d  i
t  i  o  n  a  l     t  y  p  e     o  f-  + \n  a  d  j  o  i  n  t+
+ p+ r+ o+ b+ l+ e+ m+  + e+ v+ e+ n+  + f+ o+ r+  + t+ h+ e+  + s+ i+
m+ p+ l+ e+  + f+ o+ r+ m+ s+  + o+ f+  + t+ h+ e+  + d+ i+ f+ f+ e+ r
+ e+ n+ t+ i+ a+ l+  + e+ q+ u+ a+ t+ i+ o+ n+  + a+ n+ d+  + t+ h+ e
+  + n+ o+ n+ l+ o+ c+ a+ l+  + c+ o+ n+ d+ i+ t+ i+ o+ n+ s+ .+  + D+
u+ e  \n+ t+ o+  + t+ h+ e+ s+ e+  + f+ a+ c+ t+ s+ ,+  + s+ o+ m+ e+
+ s+ e+ r+ i+ o+ u+ s+  + d+ i+ f+ f+ i+ c+ u+ l+ t+ i+ e+ s+  + a+ r+
i+ s+ e+  + i+ n+  + t+ h+ e+  + a+ p+ p+ l+ i+ c+ a+ t+ i+ o+ n+  + o
+ f+  + t+ h+ e+  + c+ l+ a+ s+ s+ i+ c+ a+ l+  + m+ e+ t+ h+ o+ d+ s
+  + t+ o+  + s+ u+ c+ h+  + a+ \n  p  r  o  b  l  e  m-  - e- v- e-
n-  - f- o- r-  - t- h- e-  - s- i- m- p- l- e-  - f- o- r- m- s-  -
o- f-  - t- h- e-  - d- i- f- f- e- r- e- n- t- i- a- l-  - e- q- u-
a- t- i- o- n-  - a- n- d-  - t- h- e-  - n- o- n- l- o- c- a- l-  -
c- o- n- d- i- t- i- o- n- s  .   - D- u- e-  - t- o-  - t- h- e- s-
e-  - f- a- c- t- s- ,-  - s- o- m- e-  - s- e- r- i- o- u- s-  - d-
i- f- f- i- c- u- l- t- i- e- s-  - a- r- i- s- e-  - i- n-  - t- h-
e-  - a- p- p- l- i- c- a- t- i- o- n-  - o- f-  - t- h- e-  - c- l-
a- s- s- i- c- a- l-  - m- e- t- h- o- d- s-  - t- o-  - s- u- c- h-
- a-  - p- r- o- b- l- e- m- .'

How come the rest of the text after the "adjoint" word is marked as an
additional text (while others is deleted) while in fact those text are
contained in both d1 and d2?The only difference is that it has a
newline. I'm I missing something? Is there a way for me to disregard
the newlines and spaces?

Python 2.3
WINXP

Thanks.
Jen




More information about the Python-list mailing list