1. Learn
  2. /
  3. 课程
  4. /
  5. Python 中的软件工程原理

Connected

道练习

符合 PEP 8

正如我们所讲,已有工具可用于检查您的代码是否符合 PEP 8 指南。保持合规的一种方式是使用能在您不小心偏离风格指南时发出警告的 IDE。另一种方式是使用 pycodestyle 包检查代码。

下方结果显示了对编辑器中代码运行 pycodestyle 检查的输出。每行开头的数字表示该类型违规出现的次数。

my_script.py:2:2:  E225 missing whitespace around operator
my_script.py:2:7:  E231 missing whitespace after ','
my_script.py:2:9:  E231 missing whitespace after ','
my_script.py:5:7:  E201 whitespace after '('
my_script.py:5:11: E202 whitespace before ')'

说明

100 XP
  • 利用 pycodestyle 的输出,编辑代码以符合 PEP 8。