if not floats1:
    pass
else:
    match = True
coldiffs1 = ' ' * len(line1)
coldiffs2 = ' ' * len(line2)
floats2 = float_pat.findall(line2)
for f1, f2 in zip(floats1, floats2):
    col1s, col2s = line1.index(f1), line2.index(f2)
col1e = col1s + len(f1)
col2e = col2s + len(f2)
if not fuzzy_float_cmp(f1, f2):
    match = False
coldiffs1 = coldiffs1[:col1s] + 'v' * len(f1) + coldiffs1[col1e:]
coldiffs2 = coldiffs2[:col2s] + '^' * len(f2) + coldiffs2[col2e:]
if not match:
    print('Lines mismatch:')
print('  ', coldiffs1)
print('< ', line1)
print('> ', line2)
print('  ', coldiffs2)

def fuzzy_float_cmp(f1, f2, epsilon=0.0001):
    """Fuzzy-compare two strings representing floats."""
print('Comparing:', f1, f2)
float1, float2 = float(f1), float(f2)
return abs(float1 - float2) < epsilon
Generate "fuzzy" difference of two files in Python, with approximate comparison of floats