For 循环仅运行 1 次,而不是应有的 2 次
我有一个包含两行的列表,第一行应该触发代码的“post.locked”部分,下一行应该触发“else”部分。
如果我运行这段代码,那么它只会打印出“if”部分,而不打印出“else”部分。为什么?
for post in reddit.subreddit(content[nr].rstrip()).new(limit = 1):
if post.locked:
content[nr] = content[nr + 1]
print(post.permalink)
else:
print(post.permalink)
content[nr] = content[nr + 1]
break
I have a list of 2 lines, first one should trigget the "post.locked" part of the code and the next line should trigger the "else" part.
If I run this code then it will only print out the "if" part but not the "else" part. Why?
for post in reddit.subreddit(content[nr].rstrip()).new(limit = 1):
if post.locked:
content[nr] = content[nr + 1]
print(post.permalink)
else:
print(post.permalink)
content[nr] = content[nr + 1]
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我是个白痴 - 我不得不把整个事情放在另一个 for 循环中,如下所示:
Ok, I was an idiot - I had to put the whole thing in another for loop like this: