4308 shaares
2 results
tagged
colorama
Say you are generating a colored diff output with the standard difflib
Python package:
diff = difflib.ndiff(file1_lines, file2_lines)
print('\n'.join(diff))
Now, I'll show you how to write a simple color_diff
function that you can use to color your diff like this:
diff = difflib.ndiff(file1_lines, file2_lines)
diff …
Disclaimer: this post was heaviliy inspired by the 2 following gists:
color_log.py
usingtermcolor
recipescolorlog.py
usingcolorama
I loved the simplicity of the first, not having to manipulate any of the logging internal API, but I prefer colorama
over termcolor
.
Without further ado, there is my solution …