本文整理汇总了Python中__future__.generators方法的典型用法代码示例。如果您正苦于以下问题:Python __future__.generators方法的具体用法?Python __future__.generators怎么用?Python __future__.generators使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类__future__
的用法示例。
在下文中一共展示了__future__.generators方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transform
# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import generators [as 别名]
def transform(self, node, results):
remove_future_import(u"with_statement", node)
remove_future_import(u"nested_scopes", node)
remove_future_import(u"generators", node)
示例2: generate_children
# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import generators [as 别名]
def generate_children(count, parent, life_min, life_max):
"""We are using a generator to randomly seed a sequence of specifications for the
factory. While this is not strictly part of the Factory Pattern, it can be useful
for testing the factory or for generating objects based on some pre-defined algorithm.
It is perfectly acceptable to implement factories without generators (depends on your
specific use-case)."""
types = parent.__subclasses__()
for i in range(count):
yield {
"class_name": random.choice(types).__name__,
"lifespan": random.randint(life_min, life_max)
}