python中的mapper和reducer错误

2ul0zpep  于 2021-06-02  发布在  Hadoop
关注(0)|答案(0)|浏览(264)

当我在集群中运行mapper.py文件时,它有一个问题。错误是“strl=line.strip()中的”unexpected syntax before line“。在本地测试时没有错误。我想把文本文件中的单词存储起来,改变它们的格式,对它们进行计数,然后发送到s3 bucket中的输出。
非常欢迎指导。谢谢
Map器:

  1. import sys, re
  2. for line in sys.stdin:
  3. strl = line.strip()
  4. words = strl.split()
  5. for word in words:
  6. word = word.lower()
  7. result = ""
  8. charref = re.compile("[a-f]")
  9. match = charref.search(word[0])
  10. if match:
  11. result+= "TR2234J"
  12. else:
  13. result+= ""
  14. print result, "\t"

减速器:

  1. import sys
  2. for line in sys.stdin:
  3. line = line.strip()
  4. new_word =""
  5. words = line.split("\t")
  6. final_count = len(words)
  7. my_num = final_count / 6
  8. for i in range (my_num):
  9. new_word = "".join(words[i*6:10+(i*6)])
  10. print new_word, "\t"

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题