Use Python to check the application code reuse of the PY file

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.