[英]Only one instance being printed when there are many others
当试图追加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)
搜索注释时将问题附加到文件上有问题吗? 有什么我想解决的东西吗?
尽管我不确定原因,但已经找到了解决方案。
x = []
for comment in r.redditor("username").comments.new(limit=None):
if comment not in x:
x.append(comment)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.