I have just started learning python and am reading about classes .
this is the code i had written for a simple iterable class :
class maths:
def __init__(self,x):
self.a=x
def __iter__(self):
self.b=0
return self
def next(self):
if self.b <= self.a:
self.b = self.b+1
return self.b-1
else:
raise StopIteration
x=maths(5)
for l in x:
print l
for the next() method when i used the __next__
(self):
the following error was displayed
Traceback (most recent call last):
File "class.py", line 20, in <module>
for l in x:
TypeError: instance has no next() method
Can anyone elucidate on this behaviour . i saw an example in the dive into python 3 book by Mark Pilgrim that used the __next__
method . even the example did not run on my interpreter .
Thanks for taking your time off to help me !