我无法从Python脚本中运行PEP8检查。
我不想显式地运行pep8.exe,因为我想自动化这些检查,而且在不同的平台上,pep8可执行文件可能位于不同的位置。
PEP8高级用法介绍了如何在Python脚本中使用pep8。
引用一个例子:
import unittest
import pep8
class TestCodeFormat(unittest.TestCase):
def test_pep8_conformance(self):
"""Test that we conform to PEP8."""
pep8style = pep8.StyleGuide(quiet=True)
result = pep8style.check_files(['file1.py', 'file2.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")