简体   繁体   中英

How to run pylint from inside Python?

I want to run pylint on all my modules, which are in different locations in a big directory. Because running pylint in this directory is still not supported , I assume I need to walk through each module in my own Python scripts and run pylint on each module from there.

To run pylint inside a Python script, the documentation seems clear:

It is also possible to call Pylint from another Python program, thanks to the Run() function in the pylint.lint module (assuming Pylint options are stored in a list of strings pylint_options ) as:

 import pylint.lint pylint_opts = ['--version'] pylint.lint.Run(pylint_opts)

However, I cannot get this to run successfully on actual files. What is the correct syntax? Even if I copy-paste the arguments that worked on the command-line, using an absolute file path, the call fails:

import pylint.lint pylint_opts = ["--load-plugins=pylint.extensions.docparams /home/user/me/mypath/myfile.py"]
pylint.lint.Run(pylint_opts)

What am I missing?

I know that epylint exists as an alternative, and I can get that to run, but it is extremely inconvenient that it overrides the --msg-format and --reports parameters and I want to figure out what I am doing wrong.

答案是将选项分成一个列表,如以下相关问题所示:

pylint_opts = ["--load-plugins=pylint.extensions.docparams", "/home/user/me/mypath/myfile.py"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM