#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Add text to msg or mail_body in following code


    Hi all, please excuse my little knowledge, I need to make some changes to the following code, but I am really out of my depth...

    How to I 'add' or 'append' to the following code, specifically, I need to add some further text and variables to the 'msg' or 'mail_body' part. In VB it would be as simple as adding a '&' toadd more data or join another variable, for example:

    Code:
    mail_body = “CPU speed: ” + cpu + “IP address: %s” %  ipaddr
    msg = MIMEText(mail_body)
    If I wanted to add:

    Code:
    mail_body2 = "Next bit of data here..."
    I would normally do:

    Code:
    msg = MIMEText(mail_body)
    msg = msg & MIMEText(mail_body2)
    How do I do something similar in Python?

    Thanks in advance!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    Code:
    >>> 'first part'   +   'second part'
    'first partsecond part'
    >>> '########'.join(('first part', 'second part', 'third'))
    'first part########second part########third'
    >>> '(' + '), ('.join(('first part', 'second part', 'third')) + ')'
    '(first part), (second part), (third)'
    >>>
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo