<div>
</div>
<p>我不知道如何仅从<strike>列表中获取第一项</p>
<p>我正在尝试从exchangelib获取第一个/下一个日历项:</p>
<p>我的代码:</p>
<pre><code>(...)
x = 5000 # minutes in future to look for calendar items
calendar = art(
start=time,
end=time + timedelta (minutes = x),
)
for item in calendar:
print(item.subject)
</code></pre>
<p>输出:
此时间段中的所有日历项。如果我只想得到第一个/下一个项目,我需要在最后两行代码中更改什么</p>
<p>示例输出:</p>
<pre><code>First Line
Second Line
Third Line
</code></pre>
<p>想要的输出:</p>
<pre><code>First Line
</code></pre>
<p>编辑:在过去的几个月里我获得了更多的知识,现在我可以回答我自己的问题了。很简单,我可能错误地表达了自己,人们误解了我</p>
<p>解决方案:</p>
<pre><code>for item in calendar:
print(item.subject)
break # a simple break so the loop only returns the first result
</code></pre>