PRAW-将输出附加到列表

时间:2020-09-26 13:03:51

标签: praw

我正在尝试从PRAW中编辑一些代码,以便与其打印出subreddit帖子的注释,而不是将其附加到数据框中,以供进一步分析。

我要编辑的原始代码是:

from praw.models import MoreComments

for i in dat_comments_id:
    submission = reddit.submission(id=i)
    for comment in submission.comments:
        if isinstance(comment, MoreComments):
            continue           
        print(comment.body)

我最初的想法是行不通的:

subreddit_comments = []

for i in dat_comments_id:
    submission = reddit.submission(id=i)
    for comment in submission.comments:
        if isinstance(comment, MoreComments):
            subreddit_comments.append(comment)

它不会给我列出所有评论,而是打印出所有这样的帖子ID:

<MoreComments count=591, children=['dmh6ry8', 'dmgt4w1', 'dmgsdrf', '...']>,
 <MoreComments count=747, children=['dimdq81', 'dimps03', 'dime3no', '...']>,
 <MoreComments count=818, children=['do2y328', 'do2m468', 'do2o35v', '...']>,
 <MoreComments count=21, children=['di8cx4x', 'di8380y', 'di826lg', '...']>,
 <MoreComments count=370, children=['djk11xc', 'djkfd37', 'djkd0qs', '...']>,
 <MoreComments count=591, children=['dmh6ry8', 'dmgt4w1', 'dmgsdrf', '...']>,
 <MoreComments count=747, children=['dimdq81', 'dimps03', 'dime3no', '...']>,
 <MoreComments count=818, children=['do2y328', 'do2m468', 'do2o35v', '...']>,
 <MoreComments count=21, children=['di8cx4x', 'di8380y', 'di826lg', '...']>,
 <MoreComments count=370, children=['djk11xc', 'djkfd37', 'djkd0qs', '...']>]

我如何编辑代码,以便它附加原始输出而不是打印输出?

1 个答案:

答案 0 :(得分:0)

我想我偶然发现了一个答案。我仍然愿意接受更熟悉PRAW的任何人提供的更好的选择。

<img/>