在 阅读 https://github.com/vitonzhang/objc_dep 中的 objc_dep.py 时遇到:
objc_files = (f for f in files if f.endswith(ext))
在Ref[1] PEP中,这种语法称为 Generator Expressions。
例如:
g = (x**2 for x in range(10))
print g.next()
等价于:
def __gen(exp):
for x in exp:
yield x**2
g = __gen(iter(range(10)))
print g.next()
Reference
1. PEP 289 - Generator Expressions
https://www.python.org/dev/peps/pep-0289/