对象使用多个很长的方法连接怎样排版?

诸如下面这种的,数据一长格式排版就不好看了,不知道如何排版是好?

result = Animal.filter(name='dog', sex='female', age='2', color='yellow').limit(100).order(born)
阅读 4.9k
3 个回答

可参考PEP8中对缩进的建议。

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)

No:

# Arguments on first line forbidden when not using vertical alignment
foo = long_function_name(var_one, var_two,
    var_three, var_four)

# Further indentation required as indentation is not distinguishable
def long_function_name(
    var_one, var_two, var_three,
    var_four):
    print(var_one)

Optional:

# Extra indentation is not necessary.
foo = long_function_name(
  var_one, var_two,
  var_three, var_four)
result = Animal.filter(
        name='dog',
        sex='female',
        age='2',
        color='yellow'
    ).limit(100).order(born)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题