首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python中的Class.main编程风格

Python中的Class.main编程风格
EN

Stack Overflow用户
提问于 2022-06-16 14:23:03
回答 1查看 40关注 0票数 0

有人能告诉我这行代码在执行什么吗?

代码语言:javascript
复制
if __name__ == "__main__":
    TwitterHarvester.main(TwitterHarvester, QUEUE, [SEARCH_ROUTING_KEY, TIMELINE_ROUTING_KEY])

这是一个python文件,包含一个名为TwitterHarvester的类,它没有定义主函数。有人能告诉我这条电话在打什么吗?

这是功能的起点;

代码语言:javascript
复制
class TwitterHarvester(BaseHarvester):
    def __init__(self, working_path, stream_restart_interval_secs=30 * 60, mq_config=None, debug=False,
                 connection_errors=5, http_errors=5, debug_warcprox=False, tries=3):
        BaseHarvester.__init__(self, working_path, mq_config=mq_config,
                               stream_restart_interval_secs=stream_restart_interval_secs,
                               debug=debug, debug_warcprox=debug_warcprox, tries=tries)
        self.twarc = None
        self.connection_errors = connection_errors
        self.http_errors = http_errors

    def harvest_seeds(self):
        # Create a twarc
        self._create_twarc()

        # Dispatch message based on type.
        harvest_type = self.message.get("type")
        log.debug("Harvest type is %s", harvest_type)
        if harvest_type == "twitter_search":
            self.search()
        elif harvest_type == "twitter_filter":
            self.filter()
        elif harvest_type == "twitter_sample":
            self.sample()
        elif harvest_type == "twitter_user_timeline":
            self.user_timeline()
        else:
            raise KeyError

    def _create_twarc(self):
EN

回答 1

Stack Overflow用户

发布于 2022-06-16 14:38:37

TwitterHarvester扩展了BaseHarvester。因此,如果TwitterHarvester没有主函数,那么它应该在BaseHarvester中。

谷歌告诉我,基地收割机是sfm-utils包的一部分。导入行是这里

代码语言:javascript
复制
from sfmutils.harvester import BaseHarvester, Msg

因此,我在sfm-utls源代码中找到了:

代码语言:javascript
复制
class BaseHarvester(BaseConsumer):
    """
    Base class for a harvester, allowing harvesting from a queue or from a file.
    ...
    """
    ...
    @staticmethod
    def main(cls, queue, routing_keys):
        """
        A configurable main() for a harvester.

给你:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72647447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档