python implementation: remove spaces and line breaks, differences compare two text files text content, and outputting a difference value

Coding #: utf-8 
# preparation, the generated file transfer by t2.text to Notepad ++ utf-8 encoded
# result is output as a first difference data existence
# modify every time a new file requires t2.text transcoding
os Import
os.chdir ( "D: / tesseract / T2") to change the file directory #
# os.system ( "dir")
#python 3.x
#python compare the contents of two files

with open ( "t2.txt", " R & lt ", encoding =" UTF-. 8 ") AS file1, \
Open (" named text.txt in "," R & lt ", encoding =" UTF-. 8 ") AS file2:
FA = file1.read ()
FB = file2.read ()
FA = fa.replace ( "", "")
FA = fa.replace ( "\ n-", "")
FB = fb.replace ( "", "")
FB = fb.replace ( "\ n-" , "")
the STA = len (FA)
stb = len (fb)
! = IF the STA stb:
print ( "error unequal length")
for m in Range (STA):
IF FA [m] == FB [m]:
In Flag = -1
the else:
In Flag =. 1
Print (FA [m])
Print (FB [m])
BREAK
IF In Flag ==. 1:
Print ( 'difference data existence')
elif In Flag == -. 1:
Print ( "data consistency")
Print ( "finish")

Note: in the above code, Python points although the global and local variables, but for the if statement and, within the scope thereof and an outer scope is the same scope, for the variable which is the reason the flag can be used if the

Guess you like

Origin www.cnblogs.com/zzh99/p/11896919.html