我正在尝试在Python中编写基本的字数统计MapReduce。这是映射器代码:

#!/usr/bin/env python

import sys
# input comes from STDIN (standard input)
for line in sys.stdin:

    try:
        # remove leading and trailing whitespace
        line = line.strip()
        # split the line into words
        words = line.split()
        # loop over words
        for word in words:
        # write out word and trivial count
            print '%s\t%s' % (word.strip(), 1)
    except:
        pass

我正在从Guttenberg项目运行Ulysses。

当我在Hadoop集群上运行它时,出现以下错误消息:
    File "<stdin>", line 1
    The Project Gutenberg EBook of Ulysses, by James Joyce
              ^
SyntaxError: invalid syntax

我没有错,有帮助吗?

最佳答案

看来您可能正在尝试将本书作为Python文件运行。也许您正在以错误的顺序将参数传递给某些东西。

09-11 02:39