[PRAW] Problem with choosing post relevance from dictionary?

PRAW

So I have this code:

subreddit = reddit_obj.subreddit("ProgrammerHumor")
post_types = {
	"hot"    : subreddit.hot,
	"new"    : subreddit.new,
	"top"    : subreddit.top,
	"rising" : subreddit.rising, 
}
post_type = input("What post type?: ")
post_time = input("What time range?:")
posts = post_types[post_type](post_time)

This was my thought process:
What I was trying to do was make it so I could have one function get posts of type X at time Y. By time I'm referring to like, hour, day, month, etc, so I didn't have to make a function for each post type since that would be inefficient, and I didn't want to have a bunch of elif statements since that would be kinda long. I decided to have a dictionary with the post type as a key, and it's corresponding method as a reference in the value.
The error I was getting was:

Traceback (most recent call last):
  File "E:\Programming\Reddit Scraper\main.py", line 45, in <module>
    posts = post_types[post_type](post_time)
TypeError: hot() takes 1 positional argument but 2 were given

I'm not passing any kwargs, and the only positional argument that I'm passing into it, is the time from user input.

What I've tried: So far the only other idea I had was to try using getattr() instead of indexing a dictionary, but I ended up getting the exact same error.

What am I doing wrong here? Also sorry if this is a bit long, I rarely post on Reddit, I usually comment.

Posted Apr 9, 2020, 7:08 PM UTC

33
Watchful1RemindMeBot &amp; UpdateMeBot•

I'm not sure what the default argument is for a ListingGenerator, but it's not the time span. You need to specify what argument you're passing in.

post_types[post_type](t=post_time)

But on top of that, hot doesn't even take a timespan. Neither does new or rising. Only top does.

2
[deleted]•

[deleted]

1
m1ss1ontomars2k4•

The hidden first positional argument is probably self, by the way.

2