Can someone help please
gherron at digipen.edu
Thu Jul 21 13:41:20 EDT 2011
On 07/21/2011 10:23 AM, Billy Mays 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
>> 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().
That won't work (You must not have even tried to run this.) The call
f.readlines() returns a list which causes an error when added to a string:
TypeError: cannot concatenate 'str' and 'list' objects
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
More information about the Python-list