DiffLib Question
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon May 7 03:12:22 EDT 2007
En Mon, 07 May 2007 00:52:18 -0300, whitewave <fruels at gmail.com> escribió:
> 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)
So you are concerned with character differences, ignoring higher order
structures. Use a linejunk filter function to the Differ constructor -as
shown in my post last Wednesday- to ignore "\n" characters when matching.
That is:
def ignore_eol(c): return c in "\r\n"
fileDiff = difflib.Differ(linejunk=ignore_eol).compare(f1, f2)
print ''.join(fileDiff)
you get:
- 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+ a+ n+ 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 } .
--
Gabriel Genellina
More information about the Python-list
mailing list