Python-获取win32com类的所有属性的列表

时间:2018-08-06 01:05:26

标签: python properties attributes win32com

我是Python的新手。我必须从Outlook中提取电子邮件并获取电子邮件的所有属性/属性。

一个接一个地检索属性,因为我知道它们存在的属性/属性可以正常工作(.Subject,.Body等)。

但是,我需要获取所有可能的属性。那就是我的问题所在。 我一直在找几个小时,发现的唯一答案是:

  • vars()
  • dir()
  • inspect.getmembers(obj)
  • __dict__
这没有给我像以下属性的列表:

  • 。主题
  • 。身体
  • .SentOn
有人可以帮忙吗?

这是我的测试笔记本的摘录:

####### Retrieve email from Outlook #######
import win32com.client
objOutlookMAPI=win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
​    
​### Define folder
objOlFolder = objOutlookMAPI.GetDefaultFolder(6)

​### Retrieve ant print email
objOlMessages = objOlFolder.Items
​
# objMessage : class 'win32com.client.CDispatch'
objMessage = objOlMessages.GetLast()
print(objMessage.Subject)    

> Are you going to Las Vegas for Black Hat, DefCon, Bsides, or Hacking Diversity? Either or join us on our adventures!

vars(objMessage)

> {'_builtMethods_': {},
 '_enum_': None,
 '_lazydata_': (<PyITypeInfo at 0x0000021EC7B7D170 with obj at 0x0000021EC7B4B2F8>,
  <PyITypeComp at 0x0000021EC7B7D620 with obj at 0x0000021EC7B4B058>),
 '_mapCachedItems_': {},
 '_oleobj_': <PyIDispatch at 0x0000021EC7B7D290 with obj at 0x0000021EC7B4AAA8>,
 '_olerepr_': <win32com.client.build.LazyDispatchItem at 0x21ec8a7ba90>,
 '_unicode_to_string_': None,
 '_username_': 'GetLast'}


    dir(objMessage)
    #import inspect
    #inspect.getmembers(objMessage)

> [`'_ApplyTypes_'`,
 `'_FlagAsMethod'`,
 `'_LazyAddAttr_'`,
 `'_NewEnum'`,
 `'_Release_'`,
 `'__AttrToID__'`,
 `'__LazyMap__'`,
 `'__bool__'`,
 `'__call__'`,
 `'__class__'`,
 `'__delattr__'`,
 `'__dict__'`,
 `'__dir__'`,
 `'__doc__'`,
 `'__eq__'`,
 `'__format__'`,
 `'__ge__'`,
 `'__getattr__'`,
 `'__getattribute__'`,
 `'__getitem__'`,
 `'__gt__'`,
 `'__hash__'`,
 `'__init__'`,
 `'__init_subclass__'`,
 `'__int__'`,
 `'__le__'`,
 `'__len__'`,
 `'__lt__'`,
 `'__module__'`,
 `'__ne__'`,
 `'__new__'`,
 `'__reduce__'`,
 `'__reduce_ex__'`,
 `'__repr__'`,
 `'__setattr__'`,
 `'__setitem__'`,
 `'__sizeof__'`,
 `'__str__'`,
 `'__subclasshook__'`,
 `'__weakref__'`,
 `'_builtMethods_'`,
 `'_enum_'`,
 `'_find_dispatch_type_'`,
 `'_get_good_object_'`,
 `'_get_good_single_object_'`,
 `'_lazydata_'`,
 `'_make_method_'`,
 `'_mapCachedItems_'`,
 `'_oleobj_'`,
 `'_olerepr_'`,
 `'_print_details_'`,
 `'_proc_'`,
 `'_unicode_to_string_'`,
 `'_username_'`,
 `'_wrap_dispatch_'`]

1 个答案:

答案 0 :(得分:1)

为了后人,我在这个页面的 AppointmentItem 对象中找到了我需要的东西:

Outlook Visual Basic for Applications (VBA) reference

只需在页面左侧展开该对象,然后展开属性即可。在那里找到了我需要的一切。也是一个 MeetingItem 对象,仍在找出差异的过程中(这听起来很明显,但我收到的很多约会实际上都是会议(即有与会者)。

相关问题