gpt4 book ai didi

python - 先生工作 :- Display intermediate values in map reduce

转载 作者:可可西里 更新时间:2023-11-01 14:26:13 25 4
gpt4 key购买 nike

如何在使用 python MRJob 库运行 mapreduce 程序时在终端上显示中间值(即打印变量或列表)?

最佳答案

您可以使用 sys.stderr.write() 将结果输出到标准错误。这是一个例子:

from mrjob.job import MRJob
import sys
class MRWordCounter(MRJob):
def mapper(self, key, line):
sys.stderr.write("MAPPER INPUT: ({0},{1})\n".format(key,line))
for word in line.split():
yield word, 1

def reducer(self, word, occurrences):
occurencesList= list(occurrences)
sys.stderr.write("REDUCER INPUT: ({0},{1})\n".format(word,occurencesList))
yield word, sum(occurencesList)

if __name__ == '__main__':
MRWordCounter.run()

关于python - 先生工作 :- Display intermediate values in map reduce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14501647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com