繁体   English   中英

MapReduce:ValueError:太多值无法解包(预期2)

[英]MapReduce: ValueError: too many values to unpack (expected 2)

我在MapReduce中运行以下Python代码:

from mrjob.job import MRJob
import collections

bigram = collections.defaultdict(float)
unigram = collections.defaultdict(float)


class MRWordFreqCount(MRJob):

    def mapper(self, _, line):
        # Now we loop over lines in the system input
        line = line.strip().split()
        # go through each word in sentence
        i = 0
        for word in line:
            if i > 0:
                hist = word
            else:
                hist = ''

            word = CleanWord(word)  # Get the new word

            # If CleanWord didn't return a string, move on
            if word == None: continue

            i += 1
            yield word.lower(), hist.lower(), 1.0

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

我收到错误消息:ValueError:太多值无法解包(预期2),但我不知道为什么。 有什么建议么? 我正在运行的cmd行代码是: python myjob.py Test.txt --mapper

在MapReduce作业中,您仅发出键和值对。 为此,您可以应用以下类型的策略:

yield (word.lower(), hist.lower()), 1.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM