Last active
December 19, 2017 00:40
-
-
Save BlogBlocks/45f471b4ec844ed4c399ce6fd261f69a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| """ | |
| Compare two files: | |
| First check number of lines then number of characters | |
| Then print the two line by line one on top of the other. | |
| """ | |
| from time import sleep | |
| from multiprocessing import Process | |
| fname0 = 'a.txt' | |
| fname1 = 'b.txt' | |
| def basecompare(fname0,fname1): | |
| Len0 = open(fname0,"r").read() | |
| length0 = len(Len0) | |
| Len1 = open(fname1,"r").read() | |
| length1 = len(Len1) | |
| if length0 == length1:print "Number of characters is equal :\n",fname0,":",\ | |
| length0,"\n",fname1,":",length1,"\n-------------\n" | |
| else: | |
| print "Number of characters is NOT equal :\n",fname0,":",\ | |
| length0,"\n",fname1,":",length1,"\n-------------\n" | |
| return | |
| def len0(fname0): | |
| with open(fname0) as f0: | |
| for i0, l0 in enumerate(f0): | |
| pass | |
| return i0 + 1 | |
| def len1(fname1): | |
| with open(fname1) as f1: | |
| for i1, l1 in enumerate(f1): | |
| pass | |
| return i1 + 1 | |
| print "File :",fname0,"has ",len0(fname0)," lines."\ | |
| "\nFile :",fname1,"has ",len1(fname1)," lines.\n-----------\n\n" | |
| count0 = 0 | |
| count1 = 0 | |
| f0 = [] | |
| f1 = [] | |
| comp0 = [] | |
| comp1 = [] | |
| def loop(fname0,count0): | |
| text1 = open(fname0,"r").readlines() | |
| for line0 in text1: | |
| count0 =count0+1 | |
| f0.extend(line0) | |
| def loop2(fname1,count1): | |
| text2 = open(fname1,"r").readlines() | |
| for line1 in text2: | |
| count1 =count1+1 | |
| f1.extend(line1) | |
| loop(fname0,count0) | |
| loop2(fname1,count1) | |
| def len1(fname1): | |
| with open(fname1) as f1: | |
| for i1, l1 in enumerate(f1): | |
| pass | |
| Numlines = i1 + 1 | |
| return Numlines | |
| def elnum0(count): | |
| Lcount0=0 | |
| elements0 = "".join(f0) | |
| elements0 = elements0.split("\n") | |
| for element in elements0: | |
| Lcount0 = Lcount0 +1 | |
| if Lcount0 == count: | |
| comp0.extend(element) | |
| print element | |
| def elnum1(count): | |
| Lcount1=0 | |
| elements1 = "".join(f1) | |
| elements1 = elements1.split("\n") | |
| for elemenT in elements1: | |
| Lcount1 = Lcount1 +1 | |
| if Lcount1 == count: | |
| comp1.extend(elemenT) | |
| print elemenT,"\n" | |
| #if comp0 != comp1: print "An error starts the line above." | |
| #if comp0.extend(element) != comp1.extend(elemenT):print "XXXXXXXXXXXXXXXXXXXXXXX ERROR." | |
| count=0 | |
| basecompare(fname0,fname1) | |
| while count < len1(fname1): | |
| elnum0(count) | |
| elnum1(count) | |
| count=count+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment