help with sending mail in Program
Tim Williams
listserver at tdw.net
Thu Jun 16 11:40:45 CEST 2005
----- Original Message -----
From: "Ivan Shevanski" <darkpaladin79 at hotmail.com>
>
> if __name__ == '__main__':
> body = 'x is',x,'y is',y,'.Lets hope that works!'
> subject = 'Neo'
> sendToMe(subject, body)
>
> I really have no idea whats going on. . .help?
>
> -Ivan
Ivan, you need to pass the body as a string, you have constructed it as a
tuple.
>>> x = 'X'
>>> y = 'Y'
>>> body = 'x is',x,'y is',y,'.Lets hope that works!'
>>> body
('x is', 'X', 'y is', 'Y', '.Lets hope that works!')
>>> type(body)
<type 'tuple'>
But you can't do the following
>>> str(body)
"('x is', 'X', 'y is', 'Y', '.Lets hope that works!')"
So you have the option of things like this
>>> 'x is ' + x +' y is ' + y + ' .Lets hope that works!'
x is X y is Y .Lets hope that works!
but that gets messy the large the the amount of items you have, these are
better.
>>> ' '.join(body) # there is a space between the ' '
'x is X y is Y .Lets hope that works!'
eg
>>> body = ' '.join('x is',x,'y is',y,'.Lets hope that works!')
or
>>> "x is %s y is %s .Lets hope that works!" % (x, y)
'x is X y is Y .Lets hope that works!'
eg
>>> body = "x is %s y is %s .Lets hope that works!" % (x, y)
You can use '\n' or '\r\n' to insert a line feed (new-line) anywhere in
the body text in any of the examples above.
HTH :)
More information about the Python-list
mailing list