我正在使用from scholarly import scholarly
从谷歌学者那里获取教授列表中25位教授的引用次数。然而,有些作者没有引文。我如何能够循环并停止迭代。我已尝试使用以下代码:
for i in professorlist:
if i in professorlist:
a = scholarly.search_author(i)
author = next(search_query)
scholarly.pprint(scholarly.fill(author, sections=['counts']))
if i not in professorlist:
print ("no citations")
但我得到了这个错误:
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-636-b3aa9d644e9f> in <module>
2 if i in professorlist:
3 a = scholarly.search_author(i)
----> 4 author = next(search_query)
5 scholarly.pprint(scholarly.fill(author, sections=['counts']))
6 if i not in professorlist:
StopIteration:
对于搜索查询中的作者: scholarly.pprint(scholarly.fill(author,sections=['counts'])) 通过
谢谢:)你是说像这样吗@
它似乎通过了,但没有返回任何结果
当您使用生成器时,您可以通过调用
next
方法获得项,就像您在提供的代码段中所做的那样;但是,如果在耗尽/空的生成器上调用此方法,则会出现StopIteration错误您可以通过如下方式将其包装到try/except块中来管理它
您还可以使用
for
循环迭代生成器;它将自动处理StopIteration错误,在生成器耗尽时退出相关问题 更多 >
编程相关推荐