Why Does This Variable Vanish?
Ben Ocean
zope at thewebsons.com
Fri May 4 01:28:45 EDT 2001
Hi;
Here's my code:
>>>
import smtplib
file = open("outfile.txt", "r")
line = file.readline()
server = smtplib.SMTP("localhost")
server.sendmail("beno at thewebsons.com", "beno at thewebsons.com", line)
server.quit()
<<<
The variable *line* in the 2nd to last line of code doesn't print anything.
Now, if I put a *print line* command after *line = file.readline()* it'll
print to screen. And if I define *line = "whatever"* and put it after the
*line = file.readline()* statement, in the exact_same_place as the *print
line* statement above, then I get an email with *whatever* in the body. So,
what in tarnation is going on?? Why doesn't variable *line* persist until
the 2nd to the last line of code? This makes no sense to me at all! Your
help is appreciated.
TIA,
BenO
More information about the Python-list
mailing list