<div id="RTEContent">I wrote a small program that compares files test1 and test2 to test3.<br> If the files are different then it copies either test1 to test3 or the reverse.<br> <br> The problem is that the although the shutil.copy2 in thefunction change_files works without error it does not copy. Can anyone see what is wrong :-<br> <br> def compare_files(file_name1, file_name2):<br> x = cmp (file_name1, file_name2)<br> return x<br> <br> def open_files(file_name):<br> file_is = open(file_name,'r')<br> file_conts = file_is.read()<br> return file_conts<br> <br> def change_files(file_1, file_2):<br> yesorno = raw_input("Do you want them to be the same Y or N ")<br> yesorno = string.upper(yesorno)<br> if yesorno == 'Y':<br> try:<br>
shutil.copy2(file_1, file_2)<br> print "copy has been done "<br> except:<br> print "it did not work"<br> <br> <br> #main<br> file_name1 = open_files("test1.txt")<br> file_name2 = open_files("test2.txt")<br> file_name3 = open_files("test3.txt")<br> import shutil<br> import string<br> <br> x = compare_files(file_name3, file_name1)<br> if x != 0:<br> print "test1 and test3 are different"<br> change_files("test1.txt", "text3.txt", file_name1)<br> else:<br> file_name1 = "test2.txt"<br> print file_name1<br> x = compare_files(file_name3, file_name2)<br> # print "x is " + str(x)<br>
if x != 0:<br> print "test2 and test3 are different"<br> change_files("test2.txt", "text3.txt")<br> print "program finished"<br> <br> </div><BR><BR>--------------------------------------------------------------------------------------------------------------------------------------<br> "<span id="en-NIV-26403" class="sup"></span>Then you will know the truth, and the truth will set you free."<br> <h3>John 8:32</h3> <span style="font-style: italic;">"</span> As Pastor Niemöller said, first they came for Piglet and I did not speak out because I was not a Disney character."<br> http://www.telegraph.co.uk/opinion/main.jhtml?xml=/opinion/2005/10/04/do0402.xml<br> <br> "When the facts change, I change my opinions, what do you do sir ?" John Keynes.<br> <br> <br><p>
                <hr size=1><font face="Arial" size="2">To help you stay safe and secure online, we've developed the all new <a href="http://us.rd.yahoo.com/mail/uk/taglines/default/security_centre/*http://uk.security.yahoo.com/"><b>Yahoo! Security Centre</b></a>.</font>