Can someone help please
pythonsky at sky.com
Thu Jul 21 19:43:48 CEST 2011
Thanks for your reply's
and sorry guys for not explaining properly
ok the problem with the code, which i never realised before, is it sends the
first txt file as the header or subject field in an email and the rest in
the body of the email which i don't want. I would like all the txt files in
the body of an email
On Thu, Jul 21, 2011 at 6:23 PM, Billy Mays <
81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> wrote:
> On 07/21/2011 01:02 PM, Gary wrote:
>> 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.
>> total = ' '
>> for i in os.listdir('.'):
>> if '.txt' in i:
>> f = open(i, 'r')
>> total += f.read()
>> message = """\
>> Subject: %s
>> """% (SUBJECT,total)
> Does the file end with '.TXT' ? This might help:
> total = ' '
> txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
> for nm in txts:
> f = open(nm, 'r')
> total += f.readlines()
> message = """\
> Subject: %s
> """% (SUBJECT,total)
> I also changed read to readlines().
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list