- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据 PEP 8,这是可以接受的(也是我过去使用过的):
result = some_function_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', 'f',
)
我的问题是,这是否也适用于函数定义,例如:
def some_function_that_takes_arguments(
a, b, c,
d, e, f,
):
return a,b,c,d,e,f
我过去所做的另一个例子:
if (this_is_one_thing
and that_is_another_thing
):
do_something()
我这样做已经有一段时间了(为了保持一致性,我的所有行> 79 col都以这种方式分开),并且想知道其他人的想法是什么。
这清楚/好看吗?这符合 PEP 8 吗?
最佳答案
根据这个doc在 PEP8 上是这样。只要缩进级别为 4 个空格,将函数声明分解为多行就可以了。
Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent [7]. When using a hanging indent the following should be considered; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line.
Yes:
# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
var_three, var_four)
# More indentation included to distinguish this from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
# Hanging indents should add a level.
foo = long_function_name(
var_one, var_two,
var_three, var_four)
作为旁注,如果您发现函数签名由于参数数量而变长,请考虑将函数分解为更多原子单元(因此遵守干净的代码原则)。
关于python - 根据 PEP 8 正确的换行格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42116221/
我有关于 PEP 代理文件的问题。我的 keystone 服务运行在 192.168.4.33:5000 上。我的 Horizon 服务正在 192.168.4.33:443 上运行。 我的 We
PEP 状态的结构和含义是什么? 这几天尝试写一个python2.7的解释器。 但是,我不知道为什么比较运算符 <> 出现在 python 2.7 中。 (它不在 python 3.0 中)找出它在
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 1 年前。 Improve
我的问题与 XACML 上下文处理程序的角色和目的有关。如果我正确理解 OASIS XACML3.0 规范,PEP 会拦截来自客户端应用程序的对某些资源或访问的请求,然后使用上下文处理程序创建适合 P
我正计划为我正在研究的项目设置一些传感器。我计划在每个装有传感器的设备上使用一个简单的xmpp客户端,并通过PEP / PubSub发布读数。 我想运行一个程序,该程序会在收到来自传感器客户端的推送通
我一直在研究 PEP-Proxy-Steelskin,以便我可以为我的 Orion Context 提供一些安全层,但是,有一些问题阻碍了我的进展。 我想使用 IDM 和 Keystone 全局实例。
如果我使用 PEP-526 作为类级变量,我必须将它们记录在类的文档字符串中,在这种情况下,我需要选择我最喜欢的方式来执行此操作。 Python 3.6.4 pylint==1.8.4 class J
我正在寻找任何 PEP 3124实现或开发过程。我对邮件列表不太熟悉,但去年Python邮件列表中似乎没有出现序列“3124”。有关于此 PEP 的一些信息吗? 最佳答案 Most of the fu
我很好奇 PEP 232 (函数的属性)也适用于类方法。最后,我认为它没有或者我做错了什么? Python 2.7.6 (default, Feb 26 2014, 12:07:17) [GCC 4.
我最近一直在尝试学习 WSGI 以及网络如何在 Python 方面工作。所以我一直在阅读 Werkzeug 和 PEP333 来学习。 但是我遇到了一个小问题,我认为我理解但可能不理解,所以我希望您能
我必须在 Python 中声明一些 dict。我写了这样一段代码: class MegaClass(object): _activation_grad_classes = \ {
PEP-484 为类型注释提供了语义。这些非常适合 a) 文档和 b) IDE 帮助。它们不太适合代码优化。 例如,不幸的是,Cython 无法使用 PEP 484 注释 https://groups
假设我有一个函数会根据字符串输入参数返回一个类,如下所示: def foo(bar): if bar == 'baz': return Baz() else:
我正在开发一个大型 Python 程序,它根据命令行选项使用大量模块,特别是 numpy。我们最近发现需要在一个小的嵌入式模块上运行它,它排除了 numpy 的使用。从我们的角度来看,这很容易(只是不
我正在使用 PyCharm 和选项卡。如果有一个需要传递多个参数的函数,我可以这样做,效果很好: return render( request, '/post/list.html',
接受PEP 448 在 Python 3.5 中引入了其他解包通用化。 例如: >>> l1 = [1, 2, 3] >>> l2 = [4, 5, 6] # unpack both iterable
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 8 年前。 Improve
我对 PEP 8 中的样式有疑问(或将每行中的字符数减少到更小)。 假设我有一本包含许多不同属性的book,我想将它们连接成一些字符串。 books = [book_1, book_2, book_3
在PEP 8 Style Guide for Python Code , Naming Conventions 下列出的第一条规则是首要原则。 Overriding Principle Names t
我在 python 中有一个函数,它返回一个类而不是一个实例。如何指示返回值是特定类型的子类? 在下面的例子中,我将返回值设置为类型,但我想进一步说明该类型具有BaseClass的所有属性: from
我是一名优秀的程序员,十分优秀!