当有许多其他实例时只打印一个实例

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)

尽管此代码仅 returns 一个实例 comment 下面的代码 returns 适当的数量。

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)