Get all attributes of a com object

E

eicwo01

Without to know the names, is it possible to dump all attributes of a
com object?
from win32com.adsi import *
objDom = ADsOpenObject("LDAP:/ ...
print ???"all attributes"??? of objDom

Thanks
Wolfgang
 
B

bruno at modulix

eicwo01 said:
Without to know the names, is it possible to dump all attributes of a
com object?
from win32com.adsi import *

<ot>
from module import * is Bad(tm)
objDom = ADsOpenObject("LDAP:/ ...
print ???"all attributes"??? of objDom

Look at dir() and the inspect module.
 
E

eicwo01

Thanks for your tips.
But dir() and inspect did not really help.

dir():
['GetIDsOfNames', 'GetTypeInfo', 'GetTypeInfoCount', 'Invoke',
'InvokeTypes', 'QueryInterface', '_ApplyTypes_', '_FlagAsMethod',
'_LazyAddAttr_', '_NewEnum', '_Release_', '__AttrToID__',
'__LazyMap__', '__call__', '__cmp__', '__doc__', '__getattr__',
'__getitem__', '__init__', '__int__', '__len__', '__module__',
'__nonzero__', '__repr__', '__setattr__', '__setitem__', '__str__',
'_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_']

pprint.pprint(inspect.getmembers(objDom)):
[('GetIDsOfNames',
<built-in method GetIDsOfNames of PyIDispatch object at 0x00AB7BFC>),
('GetTypeInfo',
<built-in method GetTypeInfo of PyIDispatch object at 0x00AB7BFC>),
('GetTypeInfoCount',
<built-in method GetTypeInfoCount of PyIDispatch object at
0x00AB7BFC>),
('Invoke', <built-in method Invoke of PyIDispatch object at
0x00AB7BFC>),
('InvokeTypes',
<built-in method InvokeTypes of PyIDispatch object at 0x00AB7BFC>),
('QueryInterface',
<bound method ADSIDispatch.QueryInterface of <COMObject Dispatch
wrapper around <PyIDispatch at 0xab7bfc with obj at 0x2625c8>>>),
('_ApplyTypes_',
<bound method ADSIDispatch._ApplyTypes_ of <COMObject Dispatch
wrapper around <PyIDispatch at 0xab7bfc with obj at 0x2625c8>>>),
...
Further more this nice method also did not know any more:
objDom._print_details_():

AxDispatch container Dispatch wrapper around <PyIDispatch at 0xab7bfc
with obj at 0x2625c8>
Methods:
Props:
Get Props:
Put Props:

Any additional hint ?
Could it be, that you must know in advance, what to ask a com object;
so there is no dump possibility ?

Thanks
Wolfgang
 
B

bruno at modulix

eicwo01 said:
Thanks for your tips.
But dir() and inspect did not really help.

Really ?

def dump(obj):
for name in dir(obj):
print getattr(obj, name)
 
D

Duncan Booth

bruno said:
Really ?

def dump(obj):
for name in dir(obj):
print getattr(obj, name)

That will show him the attributes of the Python wrapper around the COM
object, it won't show him the attributes of the underlying COM object
itself.

If I remember correctly (and its a while since I did this), you may be able
to use win32com/client/makepy.py to generate a .py file from a type
library. If you do this then the python wrapper will have methods to
forward the calls, so you can inspect it as above. Unfortunately, not all
COM objects have to have type libraries, so it isn't always possible to do
this and then you have to fall back on reading the documentation for
whatever COM object you are using.

You can also embed a call to gencache.EnsureModule() into your code to
generate the needed wrappers automatically: the output from makepy tells
you this.

The easy way to run makepy is to run PythonWin and use 'COM makepy utility'
from its tool menu. Then all you have to do is figure out which of the type
libraries in the system is the relevant one.
 
B

bruno at modulix

Duncan said:
bruno at modulix wrote:




That will show him the attributes of the Python wrapper around the COM
object, it won't show him the attributes of the underlying COM object
itself.

I stand corrected - and shouldn't answer questions about MS technos :(

(snip)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top