In Python, is there a way to detect the use of invalid variable names; something like VB "Option Explicit"?

I do most of my development in Java and C ++, but lately I had to write different scripts and pick Python. I run python from the command line on scripts; not interactively. I wonder if

I like a lot of things about the language, but one thing that continues to slow down my performance is that I don't get warnings in advance if I use a variable that is not yet defined.

For example, somewhere in the code, I forget the variable prefix with its declaring module, or I make a small typo, and the first time I find out about it when the program crashes.

Is there a way to get the python interpreter to give preliminary warnings if something can be funny when I access a variable that was not available or set somewhere else in the program? I understand that this is somewhat contrary to the philosophy of the language, but I cannot be the only one who makes these stupid mistakes and cannot catch them early.

+3
source share
2 answers

Pydev is pretty well integrated with Pylint, see here - and pylint is a much more powerful check than pyflakes (in addition to a minor spelling error issue, it will break style violations, etc. etc. - it is very customizable for any of your specific goals!).

+2
source

, pylint pyflakes, . pyflakes

- pyflakes, , PyFlakes:

  • , , .
  • ,
+2

Source: https://habr.com/ru/post/1712433/