How to check all types of error in a new created python file/module?

Question:

As asked in the title.. I am creating a new ‘.py’ file using python. It contains certain code which I write into the ‘.py’ file. Now, I want to check if there are any syntax errors, indentation errors etc. (in short all kinds of error) in that file. How to proceed?

P.s – I want to do it using python only and not any IDE and extensions.
P.s- Thanks in advance.

I tried using python’s os module, in that exists() function. It returns True.
Tried with python’s ‘identify’ library.

Asked By: Rdeveloper

||

Answers:

To check for all types of errors in a new Python file or module without running it, you can use a static analysis tool such as pyflakes, pylint, or mypy.

pyflakes is a simple static analysis tool that checks for syntax errors and undefined variables. To use pyflakes, you can install it using pip and then run it on your Python file or module. For example:

pip install pyflakes
pyflakes my_module.py

pylint is a more comprehensive static analysis tool that checks for a wide range of errors and issues, including syntax errors, undefined variables, coding style violations, and more. To use pylint, you can install it using pip and then run it on your Python file or module. For example:

pip install pylint
pylint my_module.py

Similarly, you can use mypy.

Answered By: Suleman Elahi
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.