Refactoring code and missing imports
Sometimes when refactoring code, you are copy and pasting functions from one file to another. It's very easy to forget to include the right import
statement to import some module, class or function
Use pylint to find errors
You can use pylint (ubuntu install link) to check your code. It will scan over all your code and report errors. However on a default run it will show you loads of output, and complain about lines that are too long, style guidelines etc. If you just want to see if you forgot to import something then there is a bad signal to noise ratio, making pylint less useful
There is a solution! Use the -E
flag to pylint and it'll only show errors, and no table, or summary at the end.
Use watch to make this easier
You can make this even easier to use, by using watch
, another helpful command. watch
runs another command every 2 seconds automatically and updates the screen with the output of this command.
Whole command
Run this command in a terminal window. You will see a list of python errors in your terminal (ignore the reference to using the default configuration). Fix those errors in your python file, and save the file. You'll soon (i.e. within seconds) see this output change, to show the outstanding problems. Keep going until all of them are gone
watch pylint -E path/to/python/file.py