Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing duplicate code in python [closed]

Tags:

python

Is there any library in python for duplicate code checker? I use python IDE and I am finding trouble refactoring my code. Are there any python library available which suggest duplicate code in the program/project?

Update: I found clone digger which as per its site,

We have tested Clone Digger on sources of several open-source projects. There are following drawbacks of the current report format:

Differences are highlighted using diff algorithm. This way of highlighting has nothing common with the abstract syntax tree based algorithm of comparing sequences of statements for similarity.

Class and function comments are taken into account during the computation of similarity, but they are not presented in the output. Therefore some clone pairs can look equal but marked as convergent.

Are there any tools better than this?

like image 577
Jack_of_All_Trades Avatar asked Apr 18 '12 15:04

Jack_of_All_Trades


People also ask

How do you remove duplicates from a loop in Python?

You can make use of a for-loop that we will traverse the list of items to remove duplicates. The method unique() from Numpy module can help us remove duplicate from the list given. The Pandas module has a unique() method that will give us the unique elements from the list given.

How do you find the duplicate code in Python?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Inspections. Select the Duplicated code fragment inspection under the General node. In the inspection options, select whether you want to view duplicates only within the same file or across the entire project.


1 Answers

Pylint has a check for similar/duplicate code: https://pylint.readthedocs.io/en/latest/technical_reference/features.html#similarities-checker

Usage:

pylint --disable=all --enable=similarities src/yourcode/
like image 92
Mark Lavin Avatar answered Oct 21 '22 15:10

Mark Lavin