I am using Python 3.5 but this book is teaching 2.7 (beats me why in 2016)
Learning Predictive Analytics with Python by Ashish Kumar Feb 15, 2016
>
Use the next() function on iterators:
cols = next(data).strip().split(',')
This is compatible across Python versions.
You could indeed swap .next()
for .__next__()
, but it is better to use the standard function here, just as you'd use len(obj)
instead of calling obj.__len__()
. Double-underscore methods are hooks used by Python, your code should use the standard APIs that may or may not call those hooks. This is especially true here, where the hook name changed.