当尝试将comment
附加到x
时,尽管还有很多实例,但仅打印comment
的一个实例。
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)
尽管此代码仅返回comment
的一个实例,但下面的代码返回了适当的金额。
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)
在搜索注释时附加到文件上是否有问题?有什么我想解决的东西吗?
答案 0 :(得分:0)
尽管我不确定原因,但已经找到了解决方法。
x = []
for comment in r.redditor("username").comments.new(limit=None):
if comment not in x:
x.append(comment)