我正在尝试写一个命令,但我不想要一条看起来不整洁的长线.我希望将字符串一起添加到命令执行.我在下面有一些代码是电子邮件功能的一部分:
msg = MIMEText("The nightly build status was a SUCCESS\n\nBuild File: http://www.python.org\n\n Build Results File: http://10.51.54.57/sandboxes/", project, "\n")
Run Code Online (Sandbox Code Playgroud)
这显示了一行,我希望有更好的方法来做到这一点.我尝试了下面的代码,但它不起作用.
msg = MIMEText("The nightly build status was a SUCCESS\n\nBuild File: ")
msg += MIMEText("http://www.python.org\n\n Build Results File: ")
msg += MIMEText("http://10.51.54.57/sandboxes/", project, "\n")
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我尝试过以下代码,但得到:
msg = MIMEText("""The nightly build status was a SUCCESS\n\n
Build File: """,
build_file, """
\n\n
Build Results File: """,
build_file, """
\n\n
Sandbox Folder:""",
sandbox, """
\n\n
Antibrick File: """,
antibrick, "\n\n")
Run Code Online (Sandbox Code Playgroud)
现在我收到消息:
Traceback (most recent call last):
File "test_email.py", line 45, in <module>
if __name__ == '__main__': myObject = email_success()
File "test_email.py", line 32, in email_success
antibrick, "\n\n")
TypeError: __init__() takes at most 4 arguments (10 given)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢S.Mark,我尝试了这个,但是当发送电子邮件时,它不是一个超链接,而是发送给:
The nightly build status was a SUCCESS
Build File: ('http://10.67.54.57/sandboxes/', '2010-01-05/new_sandbox', 'basebuild')
Build Results File: ('http://10.67.54.57/sandboxes/', '2010-01-05/new_sandbox', 'basebuild')
Sandbox Folder: ('http://10.67.54.57/sandboxes/', '2010-01-05/new_sandbox')
Antibrick File:
Run Code Online (Sandbox Code Playgroud)
尝试:
msg = MIMEText("""The nightly build status was a SUCCESS
Build File:
http://www.python.org
Build Results File:
http://10.51.54.57/sandboxes/""", project, "\n")
Run Code Online (Sandbox Code Playgroud)
如果每行开头的额外空格有问题,请使用regexp(r'^\s+')删除它们
怎么样
msg = MIMEText(
"The nightly build status was a SUCCESS\n\n"
"Build File: http://www.python.org\n\n"
"Build Results File: http://10.51.54.57/sandboxes/"
, project
, "\n"
)
Run Code Online (Sandbox Code Playgroud)
要么
msg = MIMEText("""The nightly build status was a SUCCESS
Build File: http://www.python.org
Build Results File: http://10.51.54.57/sandboxes/""", project, "\n")
Run Code Online (Sandbox Code Playgroud)
要么
msg = MIMEText("The nightly build status was a SUCCESS\n\n"
"Build File: http://www.python.org\n\n"
"Build Results File: http://10.51.54.57/sandboxes/"
, project, "\n")
Run Code Online (Sandbox Code Playgroud)
更新:因为OP增加了另一个问题
msg=MIMEText("""The nightly build status was a SUCCESS\n\n
Build File: %s
\n\n
Build Results File: %s
\n\n
Sandbox Folder: %s
\n\n
Antibrick File: """ % (build_file,build_file,sandbox),
antibrick,
"\n\n"
)
Run Code Online (Sandbox Code Playgroud)