I got error when I try executing it that is 'function' object is not 
iterable.
And I have no idea how I should improve it now.
Anybody give me some helping?
Thanks.

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe
import collections
in_file = open ('F:\ANM255\Week07\GettysburgAddress.txt', 'r')
out_file = open ('F:\ANM255\Week07\New_one.txt', 'w')
source = in_file
print source
source.read() 
def countWords(source):
    
    wordCounter = collections.defaultdict(int)
    for line in source:
        for word in line.split():
            word = word.strip(',.-').lower()
            wordCounter[word] += 1         
    if '' in wordCounter:
        del wordCounter['']  
        
    return wordCounter

def print_words(words):
    array = max(len(key) for key in words)
    forSort = words.items()
    forSort.sort()
    for key, value in forSort:
        print key.rjust(array), '\t', value

print print_words(wordCounter)

target = out_file
target.write('%s' % (print_words))
target.close()

Reply via email to