wesm / pydata-book

Materials and IPython notebooks for "Python for Data Analysis" by Wes McKinney, published by O'Reilly Media

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 3: Generator expressions

sammjohnsn opened this issue · comments

On page 76, under generator expressions, this example is shown:

In [191]: sum(x ** 2 for x in range(100))
Out[191]: 328350

However, when running the line:
sum(x ** 2 for x in range(100))

I receive the error:
"TypeError: 'int' object is not callable"

Edit:
The code only does not work in Jupyter

Sounds like you have a variable named sum or range

>>> sum(x ** 2 for x in range(100))
328350
>>> sum = 5
>>> sum(x ** 2 for x in range(100))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

Sometime in the next year I'm planning to refresh the code examples in the 2nd edition to account for pandas >= 1.1.0 and I'll make sure this is correct in the book in case there is some mistake

Thank you!