API to get a formatted diff
davidbolvansky opened this issue · 1 comments
davidbolvansky commented
Hello,
I would like to icdiff as python library but now icdiff.diff immediately prints the whole diff. I would like to get a string containing formatted diff, e.g.:
diff = icdiff.diff(a,b)
... some code ...
if (something)
sys.stdout.write(diff)
Thanks
jeffkaufman commented
It's not ideal, but you can do that by overriding stdout:
import sys
from cStringIO import StringIO
captured_stdout = StringIO()
sys.stdout = captured_stdout
icdiff.diff(a,b)
sys.stdout = sys.__stdout__
... some code ...
if (something):
sys.stdout.write(captured_stdout.getvalue())
Warning: this is just from reading docs; I haven't tested this.
Warning: I'm not making any promises about icdiff's output staying the same. If you're parsing its output and an update breaks your code, that's on you.