gpt4 book ai didi

python - wordcount:reduce python程序抛出ValueError

转载 作者:行者123 更新时间:2023-12-02 21:43:46 26 4
gpt4 key购买 nike

每当尝试在Hadoop系统中运行Reducer python程序时,都会出现此错误。 Mapper程序可以完美运行。与我的Mapper程序具有相同的权限。是否存在语法错误?

追溯(最近一次通话):
在第13行的文件“reducer.py”中
单词,计数= line.split('\ t',1)
ValueError:需要多个值才能解压

            #!/usr/bin/env python
import sys

# maps words to their counts
word2count = {}

# input comes from STDIN
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()

# parse the input we got from mapper.py
word, count = line.split('\t', 1)
# convert count (currently a string) to int
try:
count = int(count)
except ValueError:
continue

try:
word2count[word] = word2count[word]+count
except:
word2count[word] = count

# write the tuples to stdout
# Note: they are unsorted
for word in word2count.keys():
print '%s\t%s'% ( word, word2count[word] )

最佳答案

当您在右侧使用太少的值进行多重分配时,抛出ValueError: need more than 1 value to unpack错误。因此,看来line中没有\t,因此line.split('\t',1)产生单个值,从而导致类似word, count = ("foo",)的问题。

关于python - wordcount:reduce python程序抛出ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26837157/

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