Last active
May 5, 2016 09:23
-
-
Save bofm/082526ce35f955719e13c12c79d84f53 to your computer and use it in GitHub Desktop.
Simple function to print diff of two strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def diff(one, two): | |
with tempfile.TemporaryDirectory() as tmpdir: | |
f1, f2 = ('%s/%s' % (tmpdir, n) for n in (1,2)) | |
for f, txt in zip((f1, f2), (one, two)): | |
with open(f, 'w') as f: | |
f.write(str(txt)) | |
cmd = ('diff -w %s %s' % (f1, f2)).split() | |
with subprocess.Popen(cmd, | |
stderr=subprocess.PIPE, | |
stdout=subprocess.PIPE) as popen: | |
out, err = map(bytes.decode, popen.communicate()) | |
print(out) | |
print(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment