首页 > 解决方案 > Hadoop Hortonwork 沙箱中的 Python 语法错误

问题描述

我正在 Hadoop 上进行字数统计任务,我已经上传了一个映射器和一个减速器代码。(这些 mapper 和 reducer 代码在 Jupyter Notebook 中工作得很好!)

但是,当我在 Hadoop 上运行 reducer 代码时,我收到关于此行的语法错误

Dictionary2 = {word:count for [word,count] in Dictionary1.items() if word.startswith('W')}

这是我的代码:

line 1: cd usr
line 2: cd tmp
line 3: hdfs dfs -get /user/text1.txt
line 4: hdfs dfs -get /user/*.py
line 5: cat text1.txt | python mapper.py | python reducer.py

我得到的错误信息:

Dictionary2 = {word:count for [word,count] in Dictionary1.items() if word.startswith('W')}

(Note: There is an upper arrow pointing under the word 'for')

**Syntax Error: Invalid syntax** 

有谁知道是什么原因?这是因为 Jupyter 和 Hadoop 的 Python 版本不同吗?

标签: pythonhadoop

解决方案


推荐阅读