我试着写一篇关于地图缩小的作业。我在一个终端上运行:
ioannis@ioannis-desktop:~$ python hw3.py
然后在另一个终端:
^{pr2}$hw3.py:
import mincemeat
import glob
from stopwords import allStopWords
text_files = glob.glob('/home/ioannis/Web Intelligence and Big Data/Week 3: Load - I/hw3data/hw3data/*')
def file_contents(file_name):
f = open(file_name)
try:
return f.read()
except:
print "exception!!!!!!"
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():
........................
........................
if word in allStopWords:
continue
print(word)
print(words_title)
print("\n\n")
def reducefn(k, vs):
result = sum(vs)
return result
s = mincemeat.Server()
s.datasource = source
s.mapfn = mapfn
s.reducefn = reducefn
results = s.run_server(password="changeme")
print results
为什么不管用?您可以看到hw3.py和停止字.py在主目录中!在
https://github.com/michaelfairley/mincemeatpy#imports
low:将
from stopwords import allStopWords
语句移到mapfn
函数的顶部。在相关问题 更多 >
编程相关推荐