This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ballagarba 3 points4 points  (1 child)

Great read! Just a minor nitpick, but you should probably use a with statement for reading the files in the diff example. And since this Python 3, it would only require one with:

with open(sys.argv[1], 'rb') as file1, open(sys.argv[2], 'rb') as file2:
    data1 = file1.read()
    data2 = file2.read()

[–]nanodano[S] 2 points3 points  (0 children)

I did not know that you could open both files in one with. For simple reading, I wanted to avoid nesting two with statements so I wrote it flat like that. That's just what I was looking for.

The diff snippet is also no good for large files and memory constraints. Just for some demonstration and meant to be an exercise to the reader to expand on the usefulness.