首先,我查看了this、this和this,虽然第一个有一些有用的信息,但它与这里无关,因为我正在尝试迭代值。
这是我想要做的事情的一个例子:
class BlockingIter:
def __iter__(self):
while True:
yield input()
async def coroutine():
my_iter = BlockingIter()
#Magic thing here
async for i in my_iter:
await do_stuff_with(i)
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?
(注意,BlockingIter实际上是我正在使用的库(chatexchange),因此可能还有其他一些复杂情况。)
我试图获得2个无限生成器的产品,但product函数in itertools 不允许这种行为.
示例行为:
from itertools import *
i = count(1)
j = count(1)
x = product(i, j)
[Killed]
Run Code Online (Sandbox Code Playgroud)
我想要的是:
x = product(i, j)
((0,0), (0,1), (1,0), (1,1) ...)
Run Code Online (Sandbox Code Playgroud)
只要给定无限时间,组合返回的顺序无关紧要,最终将生成所有组合.这意味着给定元素组合,返回的生成器中必须有一个有限的索引.
我想创建一个一旦生成就保持静态的页面,这样我的服务器就不会浪费资源来重新生成内容。我知道记忆,但想知道 Flask 是否为此提供了内置或不同的方法。
在浏览 CustomInputFormat 主题时,我开始知道我们有一些默认输入格式,如 TextInputFormat、KeyValueInputFormat、SequencefileInputFormat 和 NlineInputFormat。
对于 TextInputFormat,从记录中读取行,行的字节偏移量用作键,内容用作值。这个字节偏移是什么以及如何将行的内容视为值请提出建议。