#!/user/bin/env python#@Time: 2018/6/5 14:58#@Author:P gidysq#@File:P ycheck.py fromOs.pathImportIsfile as Isfile fromTimeImportTime as Timeresult={}alllines=[]filename= R'C:\Users\PGIDYSQ\Desktop\fibo.py'#accessing the. py file path" "py File program code reuse degree check" "defpreoperate ():Globalalllines with open (FileName,'R', encoding='UTF-8') as FP: forLineinchFp:line=' '. Join (Line.split ()) Alllines.append (line)defifhasduplicated (Index1): forIteminchresult.values (): forItinchItem:ifIndex1 = =It[0]:returnIt[1] returnFalsedefIsinspan (INDEX2): forIteminchresult.values (): forIinchItem:ifI[0] <=index2<i[0]+i[1]: returnTruereturnFalsedefMaincheck ():GlobalResult Totallen=Len (alllines) Index1=0 whileIndex1 < TotalLen-1: Span=ifhasduplicated (INDEX1)ifspan:index1+=spanContinueIndex2= Index1 + 1 whileIndex2 <Totallen:ifIsinspan (INDEX2): Index2+ = 1Continuesrc="'des="' forIinchRange (10): ifIndex2 + 1>=Totallen: Breaksrc+ = Alllines[index1 + 1] des+ = Alllines[index2 + 1] ifsrc = =Des:t=Result.get (index1,[]) forTtinchT:ifTt[0] = =index2:tt[1] = i+1 Break Else: T.append ([Index2,i+1]) Result[index1]=TElse: BreakT=Result.get (Index1, []) forTtinchT:ifTt[0] = =Index2:index2+ = Tt[1] Break Else: Index2+ = 1Result[index1]=Result.get (index1,[]) forNinchResult[index1][::-1]: ifN[1] < 3: Result[index1].remove (n)if notResult[index1]:delResult[index1] a= [Ttt[1] forTttinchResult.get (index1,[[index1,1]])] ifa:index1+=Max (a)Else: Index1+ = 1defOutput ():Print('-'*20) Print('Result:') forKey,valueinchResult.items ():Print('The original line is : \n{0}'. Format (Alllines[key]))Print('Its line number is {0}'. Format (key+1)) Print('The duplicated line numbers is:') forIinchValue:Print('Start:', I[0],'Span:', i[1]) Print('-'*20) Print('-'*20)ifisfile (FileName): Start=Time () preoperate () Maincheck () Output ()Print('Time used:', Time ()-start)
Use Python to check the application code reuse of the PY file