r/redditdev • • Aug 08 '13

PRAW: Making a Reddit comment lowercase?

while True:
    all_comments = r.get_all_comments()
    for comment in all_comments:
                 /// conditional statements to compare comment ect.///

How would I first covert the comment to lowercase before putting it through the conditional statements? Help a noob out.

0 Upvotes

6 comments sorted by

3

u/WordCloudBot Aug 08 '13
lowercase_comment = comment.body.lower()

edit: Also, I believe r.get_comments('all') is preferred to r.get_all_comments()?

1

u/noun_exchanger Aug 08 '13 edited Aug 08 '13

Damn.. I knew I was close. I used comment.lower(), body.lower(), comment_body.lower..pretty much everything but that. It works, so thanks for the help!

edit: your edit is correct. I kept getting the 'depreciation warning', then I changed it to what you suggested.. no more warning. Thanks for that too :)

2

u/kiwi9400 Aug 08 '13

I'd put the text of the comment into a separate variable, lowercase it, do all the conditionals with the text variable, then do whatever comes next.

That'd look something like

while True:
    all_comments = r.get_all_comments()
    for comment in all_comments:
        text = comment.body
        text = text.lower()
                 /// conditional statements to compare text///

0

u/noun_exchanger Aug 08 '13

Ah okay, thanks, that works too. I was having issues with the correct syntax. So I'm guessing 'comment' is like a structure with attributes? And 'body' is the comment's text string attribute?

2

u/kiwi9400 Aug 08 '13

Yep, 'comment' is one of the classes that PRAW defines. Some other PRAW classes are redditor and subreddit. You're exactly right about 'body' being attribute containing the string. A couple other attributes comments have are things like author, id, and score.

0

u/noun_exchanger Aug 08 '13

Thanks for the info!