Download latest PDF - Read the Docs
Transcript
CHAPTER 2
Running Pylint
2.1 Invoking Pylint
Pylint is meant to be called from the command line. The usage is
pylint [options] module_or_package
You should give Pylint the name of a python package or module. Pylint will not import this package or module,
though uses Python internals to locate them and as such is subject to the same rules and configuration. You should pay
attention to your PYTHONPATH, since it is a common error to analyze an installed version of a module instead of the
development version.
It is also possible to analyze python files, with a few restrictions. The thing to keep in mind is that Pylint will try to
convert the file name to a module name, and only be able to process the file if it succeeds.
pylint mymodule.py
should always work since the current working directory is automatically added on top of the python path
pylint directory/mymodule.py
will work if “directory” is a python package (i.e. has an __init__.py file) or if “directory” is in the python path.
For more details on this see the Frequently Asked Questions.
You can also start a thin gui around Pylint (require tkinter) by typing
pylint-gui
This should open a window where you can enter the name of the package or module to check, at Pylint messages will
be displayed in the user interface.
It is also possible to call Pylint from an other python program, thanks to py_run() function in epylint module,
assuming Pylint options are stored in pylint_options string, as:
from pylint import epylint as lint
lint.py_run(pylint_options)
To silently run Pylint on a module_name.py module, and get its standard output and error:
from pylint import epylint as lint
(pylint_stdout, pylint_stderr) = lint.py_run('module_name.py', return_std=True)
5