什么是 PEP8 的 E128:为了视觉缩进而缩进不足的续行? [英] What is PEP8's E128: continuation line under-indented for visual indent?

查看:29
本文介绍了什么是 PEP8 的 E128:为了视觉缩进而缩进不足的续行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚使用 Sublime Text(使用 Sublime Linter)打开了一个文件,并注意到一个我以前从未见过的 PEP8 格式错误.正文如下:

Just opened a file with Sublime Text (with Sublime Linter) and noticed a PEP8 formatting error that I'd never seen before. Here's the text:

urlpatterns = patterns('',
    url(r'^$', listing, name='investment-listing'),
)

它正在标记第二个参数,即以 url(...)

It's flagging the second argument, the line that starts url(...)

我正准备在 ST2 中禁用此检查,但是我想知道我做错了什么,然后再忽略它.你永远不知道,如果这看起来很重要,我什至可能会改变我的方式:)

I was about to disable this check in ST2 but I'd like to know what I'm doing wrong before I ignore it. You never know, if it seems important I might even change my ways :)

推荐答案

PEP-8 建议 如果在第一行放置任何内容,则建议将行缩进到左括号,因此它应该缩进到左括号:

PEP-8 recommends you indent lines to the opening parentheses if you put anything on the first line, so it should either be indenting to the opening bracket:

urlpatterns = patterns('',
                       url(r'^$', listing, name='investment-listing'))

或者不将任何参数放在起始行,然后缩进到统一级别:

or not putting any arguments on the starting line, then indenting to a uniform level:

urlpatterns = patterns(
    '',
    url(r'^$', listing, name='investment-listing'),
)

urlpatterns = patterns(
    '', url(r'^$', listing, name='investment-listing'))

我建议通读 PEP-8 - 你可以浏览很多内容,而且它很容易理解,不像一些技术性更强的 PEP.

I suggest taking a read through PEP-8 - you can skim through a lot of it, and it's pretty easy to understand, unlike some of the more technical PEPs.

这篇关于什么是 PEP8 的 E128:为了视觉缩进而缩进不足的续行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆