[PRAW] Problems Using Base Reddit Class
As an entry into using PRAW, I'm attempting to write a bot that will scan all the comments of a submission and tally up the total number of uses of each word in the thread.
This is the code I have written so far
countList = []
wordList = []
reddit = praw.Reddit(client_id=_client_id, client_secret=_client_secret, user_agent=_user_agent)
submission = reddit.get_submission(submission_id='6pkw0q')
for comment in submission.comments.list():
words = comment.body.split()
for word in words:
if not word in wordList:
wordList.append(word)
countList.append(0)
else:
x = 0
for existingWord in wordList:
if existingWord == word:
countList[x] += 1
else:
x+=1
The error I get when I try to run is this:
AttributeError: 'Reddit' object has no attribute 'get_submission'
I don't know whether the rest of the code works since it won't run past the line that throws the error.
Any help would be appreciated
Posted Jul 26, 2017, 5:25 AM UTC
25
It looks like that came from an earlier version of PRAW, the new way is
reddit.submission('6pkw0q'). A lot of the verby names have been changed, so if you see anyr.get_it's probably old. It's usually pretty similar though, and if you can't find it in the docs it's always fine to ask here.By the way, the better data structure to use for your counter is a dictionary, where you can relate words to numbers without having to fiddle with indices like that. Take a look at these:
https://docs.python.org/3/tutorial/datastructures.html#dictionaries
https://stackoverflow.com/questions/3496518/python-using-a-dictionary-to-count-the-items-in-a-list
Thank you so much! I'll look into it. Is there somewhere where I can look up functions in the future? Whatever I was looking at was obviously outdated
http://praw.readthedocs.io/en/latest/ is the official docs page. Check out the code overview and the pages for the classes you're interested in.
I would also recommend opening up the Python interpreter in your command line and playing with the
dirfunction, which shows a list of attributes and methods to try:Perfect. Thank you
Don't forget about
help().-snip- too long.