From 56f57f894eafeda48ce118eec16ecb88dbd1b9dc Mon Sep 17 00:00:00 2001 From: Mortada Mehyar Date: Sat, 23 Jan 2016 11:36:33 +0000 Subject: [SPARK-12760][DOCS] invalid lambda expression in python example for … MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …local vs cluster srowen thanks for the PR at https://github.com/apache/spark/pull/10866! sorry it took me a while. This is related to https://github.com/apache/spark/pull/10866, basically the assignment in the lambda expression in the python example is actually invalid ``` In [1]: data = [1, 2, 3, 4, 5] In [2]: counter = 0 In [3]: rdd = sc.parallelize(data) In [4]: rdd.foreach(lambda x: counter += x) File "", line 1 rdd.foreach(lambda x: counter += x) ^ SyntaxError: invalid syntax ``` Author: Mortada Mehyar Closes #10867 from mortada/doc_python_fix. --- docs/programming-guide.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/programming-guide.md b/docs/programming-guide.md index bad25e63e8..4d21d4320c 100644 --- a/docs/programming-guide.md +++ b/docs/programming-guide.md @@ -789,9 +789,12 @@ counter = 0 rdd = sc.parallelize(data) # Wrong: Don't do this!! -rdd.foreach(lambda x: counter += x) +def increment_counter(x): + global counter + counter += x +rdd.foreach(increment_counter) -print("Counter value: " + counter) +print("Counter value: ", counter) {% endhighlight %} -- cgit v1.2.3