# !/usr/bin/env python
# -*- coding: utf-8 -
class MyIterator(object):
def __init__(self,step):
self.step=step
def next(self):
##发回下一个元素
if self.step == 0:
raise StopIteration
self.step -=1
print '-------------'
print 1+self.step+1
print '-------------'
return self.step
def __iter__(self):
return self
for e1 in MyIterator(4):
print e1
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled/mycompany/baidu api/a3.py"
-------------
5
-------------
3
-------------
4
-------------
2
-------------
3
-------------
1
-------------
2
-------------
0
Process finished with exit code 0