-1

I have a Python code file with many functions in it. I'm only using a few. Is there a tool available to remove all of the unused ones for me?

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
Wrp Yuexia
  • 89
  • 4

1 Answers1

4

As Steve mentioned in the comments, you could use Vulture.

Here's an example from the documentation

Consider the following Python script (dead_code.py):

import os

class Greeter:
    def greet(self):
        print("Hi")

def hello_world():
    message = "Hello, world!"
    greeter = Greeter()
    greet_func = getattr(greeter, "greet")
    greet_func()

if __name__ == "__main__":
    hello_world()

Calling

vulture dead_code.py

results in the following output:

dead_code.py:1: unused import 'os' (90% confidence)
dead_code.py:4: unused function 'greet' (60% confidence)
dead_code.py:8: unused variable 'message' (60% confidence)
MarredCheese
  • 17,541
  • 8
  • 92
  • 91
  • After reading this post i installed vulture and the hardest thing to do was to add it to my tools list in pyscripter. Works like a charm – Peter Hedlund Aug 28 '19 at 16:01