How can you find unused functions in Python code?

前端 未结 5 1962
时光取名叫无心
时光取名叫无心 2020-11-27 03:31

So you\'ve got some legacy code lying around in a fairly hefty project. How can you find and delete dead functions?

I\'ve seen these two references: Find unused code

5条回答
  •  一生所求
    2020-11-27 04:25

    Because of the fairly strict way python code is presented, would it be that hard to build a list of functions based on a regex looking for def function_name(..) ?

    And then search for each name and tot up how many times it features in the code. It wouldn't naturally take comments into account but as long as you're having a look at functions with less than two or three instances...

    It's a bit Spartan but it sounds like a nice sleepy-weekend task =)

提交回复
热议问题