pythonredditpraw

'ListingGenerator' object has no attribute 'top' python praw


I would like to filter the posts on (weekly top posts) time but my computer says the 'ListingGenerator' object has no attribute 'top'. What am I doing wrong?

import praw

reddit = praw.Reddit(
client_id = "",
client_secret = "",
user_agent = "",
username = "",
password = ""
)

subreddit = reddit.subreddit("unexpected").top(time_filter="week")

top_subreddit = subreddit.top(limit = 25)

for submission in top_subreddit:

print(submission.url)

Solution

  • I believe you can use the filters of time_filter and limit together as shown below, I have tested it and it works.

    
    import praw
    
    reddit = praw.Reddit(
        client_id="enter your client id here",
        client_secret="enter your client secret here",
        user_agent="0",
    )
    
    for submission in reddit.subreddit("Unexpected").top(time_filter="week", limit= 10):
        print(submission.title)