AttributeError: '<class 'praw.objects.MoreComments'>' has no attribute 'score'
<p>Not sure how to fix this? Please guide:</p>

<pre><code>import praw

r = praw.Reddit(user_agent="getting top posts from a subredit and its submissions", site_name='lamiastella')
subreddit = r.get_subreddit('iama')
top_year_subreddit = subreddit.get_top_from_year
submissions = top_year_subreddit(limit=50)
for submission in submissions:
    #submission.replace_more_comments(limit=None, threshold=0)
    all_comments = praw.helpers.flatten_tree(submission.comments)
    all_comments.sort(key = lambda comment : comment.score, reverse = True)
    top_comments = all_comments[:30]
    for comment in top_comments:
        print(comment.body)
~                             
</code></pre>

<p>The error is:</p>

<pre><code>$ python getSubmissionsFromSubreddit.py 
Traceback (most recent call last):
  File "getSubmissionsFromSubreddit.py", line 10, in &lt;module&gt;
    all_comments.sort(key = lambda comment : comment.score, reverse = True)
  File "getSubmissionsFromSubreddit.py", line 10, in &lt;lambda&gt;
    all_comments.sort(key = lambda comment : comment.score, reverse = True)
  File "/usr/local/lib/python2.7/dist-packages/praw/objects.py", line 92, in __getattr__
    raise AttributeError(msg)
AttributeError: '&lt;class 'praw.objects.MoreComments'&gt;' has no attribute 'score'
</code></pre>

<p>Here's the gist: <a href="https://gist.github.com/monajalal/e3eb0590bc0a4f757500ec423f2b6dd3" rel="nofollow">https://gist.github.com/monajalal/e3eb0590bc0a4f757500ec423f2b6dd3</a></p>

<p>I updated my code to this and still get error for retrieving top comments:</p>

<pre><code>import praw

subreddit_name = 'nostalgia'
num_submissions = 2
r = praw.Reddit(user_agent="getting top posts from a subredit and its submissions", site_name='lamiastella')
subreddit = r.get_subreddit(subreddit_name)
top_submissions = subreddit.get_top_from_year(limit = num_submissions, comment_sort='top')
for submission in top_submissions:
        submission.replace_more_comments(limit=None, threshold=0)
        all_comments = praw.helpers.flatten_tree(submission.comments)
        if len(all_comments) &gt; 100:
                print(len(all_comments))
                top_comments = all_comments.sort(key = lambda comment : comment.score, reverse = True)
                for comment in top_comments[:10]:
                        print(comment.body)
        else:
                continue
</code></pre>

<p>I get this error:</p>

<pre><code>148
Traceback (most recent call last):
  File "getSubmissionsFromSubreddit.py", line 14, in &lt;module&gt;
    for comment in top_comments[:10]:
TypeError: 'NoneType' object has no attribute '__getitem__'
</code></pre>

<p>Here's the correct answer:</p>

<pre><code>import praw

subreddit_name = 'nostalgia'
num_submissions = 2
num_top_comments = 10
num_comments_per_submission = 500
r = praw.Reddit(user_agent="getting top posts from a subredit and its submissions", site_name='lamiastella')
subreddit = r.get_subreddit(subreddit_name)
top_submissions = subreddit.get_top_from_year(limit = num_submissions, comment_limit=num_comments_per_submission, comment_sort='top')
for submission in top_submissions:
        submission.replace_more_comments(limit=None, threshold=0)
        all_comments = praw.helpers.flatten_tree(submission.comments)
        if len(all_comments) &gt; 100:
                print(len(all_comments))
                top_comments = sorted(all_comments, key=lambda comment: -comment.score)
                for comment in top_comments[:10]:
                        print(comment.body)
                        if comment.author != None:
                                print('{0}: {1}'.format('Author name', comment.author.name))
                        else:
                                print('Author account is DELETED')
                        print('{0}: {1}'.format('Comment score is', comment.score))
        else:
                continue
</code></pre>

python reddit praw reddit-api