yield 官方称是一种生成器,每每遇到这样包含这个关键字的代码,往往有些难读。
def testyield(count):
for x in xrange(count):
print "testyield"
yield testinner(x)
def testinner(count):
for x in xrange(count):
print "testinner"
yield x
testyield(10) #执行程序,不输出任何东西
for x in testyield(10): #执行程序,不输出testinner(count)方法内容
print x
for x in testyield(10): #执行程序,输出testinner(count)方法内容
for i in x:
print i