DiffLib Question

whitewave fruels at gmail.com
Sun May 6 23:52:18 EDT 2007


Hello,

I am currently doing the third option. Doing file.read() to both file
to be compared then feed the result to the compare function.

Let me give you a brief sample of what I want to achieve.

Using this code
>>> diffline=[]
>>> fileDiff = difflib.Differ().compare(f1, f2)
>>> diffline = list(fileDiff)
>>> finStr = ''.join(diffline)

With the following strings for comparison:

>>> f1 = ''' The solvable conditions and the Green's functions of linear boundary value
... problems for ordinary differential equations with sufficiently
smooth coefficients have been
... investigated in detail by other authors
\cite{CR1,CR2,CR3,CR4,CR5}.'''
>>> f2 = '''The solvability conditions and the Green's functions of linear boundary value problems for ordinary
... differential equations with sufficiently smooth coefficients have
been investigated in detail by many
... authors \cite{CR1,CR2,CR3,CR4,CR5}.'''

I get this result:

  T  h  e     s  o  l  v  a  b+ i  l- e+ i+ t+ y     c  o  n  d  i  t
i  o  n  s     a  n  d     t  h  e     G  r  e  e  n  '  s     f  u
n  c  t  i  o  n  s     o  f     l  i  n  e  a  r     b  o  u  n  d
a  r  y     v  a  l  u  e+  + p+ r+ o+ b+ l+ e+ m+ s+  + f+ o+ r+  + o
+ r+ d+ i+ n+ a+ r+ y
+ d+ i+ f+ f- p- r- o- b- l  e+ r+ e+ n+ t+ i+ a+ l+  + e+ q+ u+ a+ t+
i+ o+ n+ s+  + w+ i+ t+ h+  + s+ u+ f+ f+ i+ c+ i+ e+ n+ t+ l+ y+  +
s  m- s-  - f  o- r-    o- r- d- i- n- a- r- y-  - d- i- f- f- e- r-
e- n  t- i- a- l-  - e- q- u- a- t- i- o- n- s-  - w- i- t  h   - s-
u- f- f- i  c- i+ o  e+ f+ f+ i+ c+ i+ e  n  t- l- y-    s+  + h+ a+ v
+ e+  + b+ e+ e+ n+  + i+ n+ v+ e+ s+ t+ i+ g+ a+ t+ e+ d+  + i+ n+  +
d+ e+ t+ a+ i+ l+  + b+ y+    m- o- o- t- h-  - c- o- e- f- f- i- c-
i- e- n- t- s-  - h  a- v- e-  - b- e- e  n+ y
- i- n- v- e- s- t- i- g- a- t- e- d-  - i- n-  - d- e- t- a- i- l-  -
b- y-  - o- t- h- e- r-    a  u  t  h  o  r  s     \  c  i  t  e
{  C  R  1  ,  C  R  2  ,  C  R  3  ,  C  R  4  ,  C  R  5  }  .

Whereas, this is my expected result:

T  h  e     s  o  l  v  a  b+ i  l- e+ i+ t+ y     c  o  n  d  i  t
i  o  n  s     a  n  d     t  h  e     G  r  e  e  n  '  s     f  u
n  c  t  i  o  n  s     o  f     l  i  n  e  a  r     b  o  u  n  d
a  r  y     v  a  l  u  e-
+    p  r  o  b  l  e  m  s     f  o  r     o  r  d  i  n  a  r  y-  +
  d  i  f  f  e  r  e  n  t  i  a  l     e  q  u  a  t  i  o  n  s
w  i  t  h     s  u  f  f  i  c  i  e  n  t  l  y     s  m  o  o  t
h     c  o  e  f  f  i  c  i  e  n  t  s     h  a  v  e     b  e  e
n-
+    i  n  v  e  s  t  i  g  a  t  e  d     i  n     d  e  t  a  i
l     b  y   + m- o- t- h- e- r-    a+ n+ y+
+ a  u  t  h  o  r  s     \  c  i  t  e  {  C  R  1  ,  C  R  2  ,  C
R  3  ,  C  R  4  ,  C  R  5  }  .


Thanks,
Jen




More information about the Python-list mailing list