发生此错误是因为
您可以定义执行打印的辅助UDF,也可以使用future库将其
>>> from operator import add>>> f = sc.textFile("README.md")>>> def g(x):... print x...>>> wc.foreach(g)要么
>>> from __future__ import print_function>>> wc.foreach(print)
但是,我认为最好将
collect()RDD内容带回驱动程序,因为
foreach它在工作程序节点上执行,并且输出不一定会出现在驱动程序/
shell中(它可能会在
local模式下出现,但在运行时不会出现)集群)。
>>> for x in wc.collect():... print x



