1

Say we get a massive and very messy script that contains many lines that aren't in use.

How can we find out which lines are in use?

If the script is very short we can go with debugger step by step and see what is used but this is impractical in most cases.

Is there any tool or trick to get the lines that are not in use?

IDEs mark variables not in use, but what about function definitions that are not executed at all?

Basically how to get the lines that weren't executed in a python script specific run?

Maybe something to plot a list of numbers of lines not in use

7
  • You add test coverage for the needed functionality, and enable coverage reporting to see what lines are missed/unused Commented Aug 2, 2021 at 20:16
  • Check out Vulture to Find dead code in Python Commented Aug 2, 2021 at 20:17
  • Does this answer your question? Finding dead code in large python project Commented Aug 2, 2021 at 20:28
  • 1
    I suppose the trace module can be used directly as well (docs.python.org/3/library/trace.html) but I don't know anyone that has used it that wasn't writing something like coverage.py ;-) Commented Aug 2, 2021 at 20:40
  • 1
    @thebjorn It is also used by debuggers e.g. for breakpoints (see sys.settrace for the user's hook) Commented Aug 2, 2021 at 21:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.