在 阅读 https://github.com/vitonzhang/objc_dep 中的 objc_dep.py 时遇到:

1 objc_files = (f for f in files if f.endswith(ext))

在Ref[1] PEP中,这种语法称为 Generator Expressions。

例如:

1 g = (x**2 for x in range(10))
2 print g.next()

 

等价于:

1 def __gen(exp):
2     for x in exp:
3         yield x**2
4 g = __gen(iter(range(10)))
5 print g.next()

 

 

 


Reference

1. PEP 289 - Generator Expressions

https://www.python.org/dev/peps/pep-0289/

相关文章:

  • 2021-10-24
  • 2021-10-13
  • 2021-11-17
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2022-03-07
  • 2021-10-01
  • 2021-07-04
  • 2021-11-19
  • 2021-10-30
  • 2022-12-23
相关资源
相似解决方案