python - 当有许多其他实例时,只打印一个实例
问题描述
尝试附加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)
推荐阅读
- c++ - boost::iostreams::::copy 似乎太慢了
- javascript - 使用门户反应打开新标签
- node.js - 尽管单独的 echo 语句,脚本输出被缓冲到一条消息中?
- c# - 哪个 Unity 程序集包含项目文件夹类类型?
- python-3.x - Selenium 与代理设置抛出 UnexpectedAlertPresentException
- javascript - NodeJS - 未捕获的引用错误:未定义原始
- python - 包含成员函数的 Python 循环依赖
- spring - Spring + Wicket REST 异常处理程序
- angular - 我得到了 Angular Service 属性的两个不同的值
- machine-learning - 如何评估在 Google AI Platform 上使用内置 Linear Learner 训练的分类模型?