Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example 3-13 TypeError #3

Open
nealmcb opened this issue Apr 23, 2015 · 0 comments
Open

Example 3-13 TypeError #3

nealmcb opened this issue Apr 23, 2015 · 0 comments

Comments

@nealmcb
Copy link

nealmcb commented Apr 23, 2015

In the process of putting together an IPython Notebook with convenient worked examples from Learning Spark, I found a simple python semantic error.

Example 3-15 says:

print "Input had " + badLinesRDD.count() + " concerning lines"

which results in

TypeError                                 Traceback (most recent call last)
<ipython-input-10-078b22c97d4b> in <module>()
 ----> 1 print "Input had " + badLinesRDD.count() + " concerning lines"
  2 print "Here are 10 examples:"
  3 for line in badLinesRDD.take(10):
  4     print line

TypeError: cannot concatenate 'str' and 'int' objects

It should say something more like this:

print "Input had %d worrisome lines" % (badLinesRDD.count())

I made a gist of an ipython notebook showing the problem and the fix, with simple worked examples, which you can see (and download) here:

http://nbviewer.ipython.org/gist/nealmcb/b6d989a83adddcdd459f

I suggest including such notebooks in future editions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant