有没有办法合并 posts/comment 流?

Is there a way to combine posts/comment streams?

大虾,我可以创建subreddit.stream.comments()subreddit.stream.submissions()

对于那些不熟悉的人,上面的两个praw功能return comments/posts因为它们进来了。

有没有办法将两者结合起来?我试过使用 Python 的内置函数 zip 以及 itertoolszip_longest,但它们都只在帖子出现时给出结果.(评论 更频繁)。

找到答案:

comment_stream = subreddit.stream.comments(pause_after=-1)
submission_stream = subreddit.stream.submissions(pause_after=-1)
while True:
    for comment in comment_stream:
        if comment is None:
            break
        print(comment.author)
    for submission in submission_stream:
        if submission is None:
            break
        print(submission.title)

关键是pause_after参数。

来源:https://www.reddit.com/r/redditdev/comments/7vj6ox/can_i_do_other_things_with_praw_while_reading/dtszfzb/