When trying to append comment
to x
, only one instance of comment
is being printed despite there being many others.
with open("testingusercomments.txt", "r") as a, open("testingusercommentstmp.txt", "a") as x:
try:
for comment in r.redditor("username").comments.new(limit=None):
if comment not in a.read().split("\n"):
print(comment)
x.append(comment)
Although this code only returns one instance of comment
the code below returns the proper amount.
with open("testingusercomments.txt", "r") as a, open("testingusercommentstmp.txt", "a") as x:
try:
for comment in r.redditor("username").comments.new(limit=None):
if comment not in a.read().split("\n"):
print(comment)
Is there a problem appending to a file while searching for comments? Is there something I've missed to solve this?
Although I'm unsure of the cause, I've found a solution.
x = []
for comment in r.redditor("username").comments.new(limit=None):
if comment not in x:
x.append(comment)