简体   繁体   English

在没有\\的Python中拆分长行

[英]Split a long line in Python without \

I have a line of code in python that is way too long. 我在python中有一行代码太长了。 I'm trying to format it, but my company doesn't allow the use of "\\" to break lines. 我正在尝试格式化它,但我的公司不允许使用“\\”来打破线条。 I tried it as such, 我试过这样,

(subject, message, chatRoomMsg, chatRecipientMsg) = 
  set_mail_and_chat(user, user_dict[user])

How can I format this line to make it work, but also keep the line under 80 characters. 如何格式化此行以使其工作,但也保持该行不超过80个字符。

Split it into two: 将其分为两部分:

result = set_mail_and_chat(user, user_dict[user])
subject, message, chatRoomMsg, chatRecipientMsg = result

You can leave the opening parenthesis in the first line, and continue in the second one: 您可以在第一行中留下左括号,然后在第二行中继续:

subject, message, chatRoomMsg, chatRecipientMsg = (
    set_mail_and_chat(user, user_dict[user]))

Starting the second line with ) = is valid. ) =开始第二行是有效的。

(subject, message, chatRoomMsg, chatRecipientMsg
 ) = set_mail_and_chat(user, user_dict[user])

You can leave the opening parenthesis of function parameters in the first line, 你可以在第一行留下函数参数的左括号,

(subject, message, chatRoomMsg, chatRecipientMsg)= set_mail_and_chat(
    user, user_dict[user])

Check the style guide for more information. 查看样式指南以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM