这里定义了两个全局的变量countx 和 county
#!/usr/bin/env python
#__metaclass__ = type
nest = [[1,2],[3,4],5]
countx = 0
county = 0
def flatten(nested):
try:
for sublist in nested:
print 'sublist=',sublist
# global countx
# print 'countx = %i' % countx
# countx += 1
for element in flatten(sublist):
print 'element=',element
# global county
# print 'county = %i' % county
# county += 1
yield element
except TypeError:
print 'except'
# print countx,county
yield nested