-1

I am working on some old python code and I was wondering if there is an easy way to find out which modules are imported but never used. I have a few hundred python scripts, each importing tens of modules (most scripts where copy-pasted by some template).

2 Answers2

3

Pylint can do this. It reports "Unused import <module>" (warning named unused-import, code W0611).

This warning is enabled by default along with many others, but if you want to check for this warning specifically, you can do:

pylint --disable=all --enable=unused-import *.py
Thomas
  • 174,939
  • 50
  • 355
  • 478
0

Using Pycharm does inform you if any modules or variables are used or not. That would be good for you in my opinion as an IDE.

Saeed
  • 3,255
  • 4
  • 17
  • 36