?
=?iso-8859-1?B?TWF0dGlhcyBCcuRuZHN0cvZt?=
Hello!
I have a question about filecmp.cmp(). The short code snippet blow
does not bahave as I would expect:
import filecmp
f0 = "foo.dat"
f1 = "bar.dat"
f = open(f0, "w")
f.write("1:2")
f.close()
f = open(f1, "w")
f.write("1:2")
f.close()
print "cmp 1: " + str(filecmp.cmp(f0, f1, False))
f = open(f1, "w")
f.write("2:3")
f.close()
print "cmp 2: " + str(filecmp.cmp(f0, f1, False))
I would expect the second comparison to return False instead of True.
Looking at the docs for filecmp.cmp() I found the following: "This
function uses a cache for past comparisons and the results, with a
cache invalidation mechanism relying on stale signatures.". I guess
that this is the reason for my test case failing.
Is there someone here that can tell me how I should invalidate this
cache? If that is not possible, what workaround could I use? I guess
that I can write my own file comparison function, but I would not like
to have to do that since we have filecmp.
Any ideas?
Regards,
Mattias
I have a question about filecmp.cmp(). The short code snippet blow
does not bahave as I would expect:
import filecmp
f0 = "foo.dat"
f1 = "bar.dat"
f = open(f0, "w")
f.write("1:2")
f.close()
f = open(f1, "w")
f.write("1:2")
f.close()
print "cmp 1: " + str(filecmp.cmp(f0, f1, False))
f = open(f1, "w")
f.write("2:3")
f.close()
print "cmp 2: " + str(filecmp.cmp(f0, f1, False))
I would expect the second comparison to return False instead of True.
Looking at the docs for filecmp.cmp() I found the following: "This
function uses a cache for past comparisons and the results, with a
cache invalidation mechanism relying on stale signatures.". I guess
that this is the reason for my test case failing.
Is there someone here that can tell me how I should invalidate this
cache? If that is not possible, what workaround could I use? I guess
that I can write my own file comparison function, but I would not like
to have to do that since we have filecmp.
Any ideas?
Regards,
Mattias