1

単語を数える条件を付けて、約7500個のファイルから単語数を計算したいだけです。プログラムはこのようになります。

import glob
import mincemeat

text_files = glob.glob('../fldr/2/*')
def file_contents(file_name):
f = open(file_name)
try:
    return f.read()
finally:
    f.close()

source = dict((file_name, file_contents(file_name))
          for file_name in text_files)

def mapfn(key, value):
  for line in value.splitlines():
    list2 = [ ]
    for temp in line.split("::::"):
        list2.append(temp)
    if (list2[0] == '5'):
        for review in list2[1].split():
            yield [review.lower(),1]

def reducefn(key, value):
  return key, len(value)

s = mincemeat.Server()
s.datasource = source
s.mapfn = mapfn
s.reducefn = reducefn

results = s.run_server(password="wola")
print results

このプログラムの実行中に発生するエラーは

error: uncaptured python exception, closing channel <__main__.Client connected at 0x250f990> 
(<type 'exceptions.IndexError'>:list index out of range 
 [C:\Python27\lib\asyncore.py|read|83] 
 [C:\Python27\lib\asyncore.py|handle_read_event|444] 
 [C:\Python27\lib\asynchat.py|handle_read|140] 
 [mincemeat.py|found_terminator|96]
 [mincemeat.py|process_command|194] 
 [mincemeat.py|call_mapfn|170] 
 [projminc2.py|mapfn|21])
4

1 に答える 1