0

This might seem confusing, but I'm having trouble with PRAW. I have a file named "comments.txt". It contains a large amount of comment ids from my reddit account. Here is an example of the file:

s12345
f65432
r43532
g43546
t42255

I want to delete them using PRAW. I can manually do it, or repetively use:

comment = reddit.comment("")
comment.delete()

to delete them all, but I want an easier way to do this. How might I be able to read a comment id from the text file, and then delete the comment?

  • Hi @Anole! This should be pretty easy with a for-loop: open the file, and for each ID, do the "repetitive" thing you showed. [Here's an example from another answer](https://stackoverflow.com/a/17949545/8033766). – jarhill0 Aug 13 '20 at 22:49
  • Ok. I have tried that. Here is the code: `with open('data.txt') as f: for line in f: # For Python3, use print(line) print(line) comment = reddit.comment(line) comment.delete() if 'str' in line: break` nothing is deleting? –  Aug 13 '20 at 23:00
  • You can remove the `print()` and the bit starting with `if 'str' in line`. What you have should work, though you may need to change to `comment = reddit.comment(line.strip())`. – jarhill0 Aug 14 '20 at 00:29
  • Ah, yes. The "comment = reddit.comment(line.strip())" part worked! You are truly an amazing person <3 –  Aug 14 '20 at 02:42

0 Answers0