I am trying to figure out how to make this class work in Python 3, it works in Python 2. This is from a tutorial by D. Beasley for generators. I am new to Python and just working through tutorials online.
Python 2
class countdown(object):
def __init__(self, start):
self.count = start
def __iter__(self):
return self
def next(self):
if self.count <= 0:
raise StopIteration
r = self.count
self.count -= 1
return r
c = countdown(5)
for i in c:
print i,
Python 3, not working.
class countdown(object):
def __init__(self, start):
self.count = start
def __iter__(self):
return self
def next(self):
if self.count <= 0:
raise StopIteration
r = self.count
self.count -= 1
return r
c = countdown(5)
for i in c:
print(i, end="")