How can I check for unused import in many Python files?

后端 未结 11 2066
名媛妹妹
名媛妹妹 2020-12-13 01:58

I remember when I was developing in C++ or Java, the compiler usually complains for unused methods, functions or imports. In my Django project, I have a bunch of Python fil

相关标签:
11条回答
  • 2020-12-13 02:13

    Have a look at PyChecker. It is a debugging tool and able to find unused variables and modules.

    0 讨论(0)
  • 2020-12-13 02:13

    You can use the following user setting:

    "python.linting.pylintEnabled": true,
    "python.linting.pylintArgs": [
        "--enable=W0614"
    ]
    

    But I think, you'll need to go through all files yourself and hit "save".

    0 讨论(0)
  • 2020-12-13 02:14

    Importchecker is a commandline utility to find unused imports in Python modules.

    0 讨论(0)
  • 2020-12-13 02:16

    Use a tool like pylint which will signal these code defects (among a lot of others).

    Doing these kinds of 'pre-runtime' checks is hard in a language with dynamic typing, but pylint does a terrific job at catching these typos / leftovers from refactoring etc ...

    0 讨论(0)
  • 2020-12-13 02:22

    autoflake is an improved version of pyflakes with additional options. It uses pyflakes under the hood, I would recommend to use it instead of using pyflakes directly.

    0 讨论(0)
  • 2020-12-13 02:24

    I agree with using PyFlakes. It's like linting, but it excludes styling errors.

    UPDATE

    How to run: pyflakes <your python file> or pyflakes <your folder containing python files>

    BE CAREFUL!!!

    If you run it just with command pyflakes, it takes a really long time like it is never-ending. My hypothesis is it is trying to check every python file in your machine/folder when you call it that way.

    0 讨论(0)
提交回复
热议问题