While using function HtmlDiff() from Library difflib, if there is difference in caps of two strings it does not provide proper diff results. Two strings in two different files in this context that I used are: hostname vaijain123 and (this string is in small caps) hostname CAVANC1001CR1 (This one is in large caps) Expected behavior after diffing : It should show hostname changed (and highlight it with Yellow color) instead of this it is showing Added in one file and deleted in another file. (Highlighting them with green and red color respectively) When tried with same caps (either small or large) it shows expected behavior(highlighting the strings in yellow color). Also with numbers it works well. I think its an issue with the CAPS of letters. difflib is not able to differentiate between the caps of letters.
Can you be more precise? I tried to reproduce your problem, but I only get added/deleted chunks, nothing in yellow. Please include a script that shows what you did, and the result you expected.
You (as a human) most likely parse these lines: hostname vaijain123 hostname CAVANC1001CR1 as "two words, the first one is the same, the second word changed". But difflib sees them more or less as: "21 letters, 8 of them are the same, 13 are different". There are many more differences than matches, so it makes sense to show the changes as a complete replacement: >>> d = difflib.ndiff(["hostname vaijain123\n"], ["hostname CAVANC1001CR1\n"]) >>> print ''.join(d) - hostname vaijain123 + hostname CAVANC1001CR1 It has nothing to do with upper or lower case letters ("A" and "a" are completely different things for difflib). If the names were shorter, it might consider a match: >>> d = difflib.ndiff(["hostname vai\n"], ["hostname CAV\n"]) >>> print ''.join(d) - hostname vai ? ^^^ + hostname CAV ? ^^^ Note how the ratio changes: >>> difflib.SequenceMatcher(None, "hostname vaijain123", "hostname CAVANC1001CR1").ratio() 0.48780487804878048 >>> difflib.SequenceMatcher(None, "hostname vai", "hostname CAV").ratio () 0.75 The ratio must be 0.75 or higher for a differ to consider two lines "close enough" to show intra-line differences.