[Tutor] Dictionary File character reader

Clara Mintz jamani.sana at hotmail.com
Tue May 10 06:27:20 CEST 2011


Sorry I am completely new at python and don't understand why this function is returning an empty dictionary. I want it to take a list of files open them then return the number of characters as the value and the file name as the key. 
def fileLengths(files):    d = {}    files = []    for file in files:        reader = open(file)        for line in reader:            char = sum(len(line))        d[file] = char        reader.close    return d
Thank you sorry I don't understand what I am doing wrong. 
-Clara 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110509/d9093ce1/attachment-0001.html>


More information about the Tutor mailing list