本文整理匯總了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)
}