python-3.x - 获取 Outlook 约会后无法调用 win32com.client.Dispatch AppointmentItem 的“大小”属性
问题描述
我正在使用win32com.client访问 Outlook 应用程序。我成功地从日历中获得了约会,但我有兴趣在不进入for循环的情况下获得约会的数量。
我正在执行以下操作:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace('MAPI')
appointments = namespace.GetDefaultFolder(9).Items
appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"
restriction = "[Start] >= '" + start_date.strftime('%Y.%m.%d') + "' AND [Start] <= '" + \
end_date.strftime('%Y.%m.%d') + "'"
restricted_items = appointments.Restrict(restriction)
print(restricted_items.Size)
从这个描述 AppointmentItem API 的链接中,我发现我可以获取 Outlook 对象的大小。但它抛出一个异常
AttributeError: '<win32com.gen_py.Microsoft Outlook 15.0 Object Library._Items instance at 0x73837256>' object has no attribute 'size'
我究竟做错了什么?
顺便说一句,我想使用它来检查由于上述查询而检索到的任何约会,这样我就不会restriction
在None
.
解决方案
Restrict
返回项目集合。它不公开 Size 属性-您需要的是Count
.
如果事先不知道集合的大小(Outlook 会按需计算),请使用Items.GetFirst/GetNext
循环遍历集合中的项目。
推荐阅读
- html - 选择不带标签的自由子元素的 XPath
- typo3 - TYPO3/TypoScript - 在 DataProcessor 中使用 FIELD() 自定义排序
- node.js - NodeJS中axios和supertest的区别
- c++ - 我可以禁止临时对象作为参数吗?
- angular - Angular 9:过滤器。为什么从服务器获取数据时过滤器在角度材料表中不起作用?
- c# - 模拟.Setup(...).Returns(..); 不嘲讽
- android - 如何从存储库中获取 sharedPreferences
- python - subprocess.run 输出为空(python 3.8)
- c++ - 我可以为 GCC 和 Clang 中的单个函数启用严格的浮点行为吗?
- python - 列表框中的 Python os.system 输出值“0”