tags:

views:

154

answers:

6

Hello, I am trying to write a command but I do not want one long line that looks untidy. I am looking to add the strings together to be executed as on command. I have some code below which is part of an email function:

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")

This shows the one line, I am hoping for a better way to do this. I have tried the below code but it does not work.

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")

Thanks for any help.

I have tried the below code but get:

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")

Now I get the message:

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)

Any ideas?

Thanks S.Mark, I tried this but when the email is sent it is not as a hyperlink but sent as:

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: 
+5  A: 

Try:

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")

If the additional space at the beginning of each line is a problem, remove them with a regexp (r'^\s+')

Aaron Digulla
A: 

you can use triple quotes

>>> s="""The nightly build status was a SUCCESS

Build File: http://www.python.org

Build Results File: http://10.51.54.57/sandboxes/"""

>>> msg=MimeType(s,project,"\n")
ghostdog74
+5  A: 

How about

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"
)

Or

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")

Or

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")

UPDATE: because OP added another question

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"
)
S.Mark
+1  A: 

Python supports multi-line strings using triple quotes:

text = """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/"""
msg = MIMEText(text, project, "\n")
Tendayi Mawushe
+3  A: 

Why not

msg= MIMEText("The nightly build status was a SUCCESS\n\nBuild File: "+ \
  "http://www.python.org\n\n Bu..... ") 

etc.

(I.e., use the line continuation backslash).

Also note that the following each give you abcdef

s ="abc" "def"

s= "abc" \
     "def"

Also,

 s="""xyz
    wvu"""

gives you

'xyz\nwvu'
Joshua Fox
A: 

Hmm, what exactly is the module are you using? I am guessing, that it is deprecated, because the modern interface is email (if I've guessed your intentions correctly). More specifically, to create a MIMEText object you use this class. The signature is

email.mime.text.MIMEText(_text[, _subtype[, _charset]])
shylent