On 07/21/2011 01:02 PM, Gary wrote:
Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the directory.
I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks
total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = """\
Subject: %s
%s
"""% (SUBJECT,total)
Does the file end with '.TXT' ? This might help:
total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
for nm in txts:
f = open(nm, 'r')
total += f.readlines()
f.close()
message = """\
Subject: %s
%s
"""% (SUBJECT,total)
I also changed read to readlines().
--
http://mail.python.org/mailman/listinfo/python-list