回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在尝试正确缩进以下代码:</p>
<pre><code>RULES_LIST = [
('Name1', 1, 'Long string upto 40 chars'),
('Name2', 2, 'Long string upto 40 chars'),
('Name3', 3, 'Long string upto 40 chars'),
('Name4', 4, 'Long string upto 40 chars'),
('Name5', 5, 'Long string upto 40 chars'),
('Name6', 6, 'Long string upto 40 chars'),
('Name7', 7, 'Long string upto 40 chars'),
('Name8', 8, 'Long string upto 40 chars')
]
</code></pre>
<p>Pylint对上面的代码抱怨<code>Wrong hanging indentation.</code>,PEP8抱怨<code>E121: under-indented for hanging indent</code>。</p>
<p>pylint的一个可能的解决方案是将其更改为:</p>
<pre><code>RULES_LIST = [\
('Name1', 1, 'Long string upto 40 chars'),
...
('Name8', 8, 'Long string upto 40 chars')]
</code></pre>
<p>但是PEP8抱怨<code>E121 and E502</code></p>
<p>PEP8:1.5.7(默认配置)<br/>
Pylint:1.3.0(默认配置)<br/>
Python:2.7.5(在OSX 10.9.3上运行)</p>
<p>名单可能会变长。有人能为这个建议一个适当的缩进吗?</p>