Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python在不需要数据时返回数据_Python_Return_Reddit - Fatal编程技术网

Python在不需要数据时返回数据

Python在不需要数据时返回数据,python,return,reddit,Python,Return,Reddit,我正在使用reddit库从reddit中提取数据,我遇到了一些代码,我不明白为什么它会返回任何数据(在BaseReddit()类中): def get_content(self,page_url,limit=0,url_data=None,place_holder=None, root_field='data',thing_field='children', 在_field='after')之后: “”“从URL返回reddit内容的生成器方法。开始于 初始页面的url,并使用`after` J

我正在使用reddit库从reddit中提取数据,我遇到了一些代码,我不明白为什么它会返回任何数据(在BaseReddit()类中):

def get_content(self,page_url,limit=0,url_data=None,place_holder=None,
root_field='data',thing_field='children',
在_field='after')之后:
“”“从URL返回reddit内容的生成器方法。开始于
初始页面的url,并使用`after` JSON数据获取内容
直到“limit”条目被提取,或者“place_holder”被删除
达到。
:param page_url:开始从中获取内容的url
:param limit:要获取的最大内容条目数。如果

limit它是一个生成器。有关这一点的提示,请参阅
yield
语句


这是一个生成器函数,您可以通过
yield
语句来判断。该值实际上是“返回”的,而不是从函数中实际返回。当从函数中请求另一个值时,生成器从它产生的点恢复(根据下面的代码,继续
for thing
循环…)

简单的例子:

def blah():
    for i in xrange(5):
        yield i + 3

numbers = blah()
print next(numbers)
# lots of other code here...
# now we need the next value
print next(numbers)
for thing in root[thing_field]:
    yield thing
def blah():
    for i in xrange(5):
        yield i + 3

numbers = blah()
print next(numbers)
# lots of other code here...
# now we need the next value
print next(numbers)