在Python3.2中,我可以这样做:
foo = Bar()
foo.setSomething(something1).setStatus('horizontal').setAttributes(attributes)
最终链条变得很长。我有一个垂直链接的痒。
foo = Bar()
foo.setSomething(something1)
.setStatus('vertical')
.setAttributes(attributes)
有没有办法做到这一点?
答案 0 :(得分:2)
将表达式括在括号中:
foo = Bar()
(foo.setSomething(something1)
.setStatus('vertical')
.setAttributes(attributes))
答案 1 :(得分:2)
谢谢@Krotton的答案确实有效。还要感谢link的@sean。因此,使用垂直链接的正确方法是:
foo = Bar()
(foo.setSomething(something1)
.setStatus('vertical')
.setAttributes(attributes))
您也可以使用语法(如多行字符串)来允许垂直链接:
foo = Bar()
foo.setSomething(something1)\
.setStatus('vertical')\
.setAttributes(attributes)