#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Indexed properties of COM objects


    Hi all,

    I have a bit of a problem. This is the brief snip of the code

    fluid = win32com.client.Dispatch('Fluid')
    fluid.NumberofComponents
    fluid.Composition.ComponentName(1)
    fluid.Composition.ExtraInfoText

    I create an object, and I can access all methods and properties, except the indexed ones (ComponentNames()). Then I get the error

    "Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python27\lib\site-packages\win32com\client\dymanic.py", line 522, in _getattr_
    raise AttributeError("%s.%s" % (self._username_,attr))
    AttributeError: <unknown>.ComponentName"

    I tried putting [] parenthesis, but the object is not subscriptable. Is there some other way to access these properties?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    The attribute isn't there. That problem occurs first. Use this code to figure out what is accessible.
    Code:
    import pprint
    fluid = win32com.client.Dispatch('Fluid')
    fluid.NumberofComponents
    print('directory of fluid')
    pprint.pprint(dir(fluid))
    print('\n\n\ndirectory of fluid.Composition')
    pprint.pprint(dir(fluid.Composition))
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    OK, this is the result for both objects
    ['_ApplyTypes_',
    '_FlagAsMethod',
    '_LazyAddAttr_',
    '_NewEnum',
    '_Release_',
    '__AttrToID__',
    '__LazyMap__',
    '__call__',
    '__doc__',
    '__eq__',
    '__getattr__',
    '__getitem__',
    '__init__',
    '__int__',
    '__len__',
    '__module__',
    '__ne__',
    '__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_']

    And this is for the property that I can not access.
    ['__call__',
    '__class__',
    '__cmp__',
    '__delattr__',
    '__doc__',
    '__format__',
    '__func__',
    '__get__',
    '__getattribute__',
    '__hash__',
    '__init__',
    '__new__',
    '__reduce__',
    '__reduce_ex__',
    '__repr__',
    '__self__',
    '__setattr__',
    '__sizeof__',
    '__str__',
    '__subclasshook__',
    'im_class',
    'im_func',
    'im_self']


    When I type only the property's name without any index, I get this
    <bound method CDispatch.ComponentName of <COMObject <unknown>>>

    I used these libraries to create sample programs in C++, C#, Fortran, Java Script, Matlab and VB, and had no trouble whatsoever. Now we have a client that uses Python, and I am completely new to it.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Do you have access to the source? Maybe the __getattribute__ method imports or diverts.

    I haven't used com objects. Maybe __getattribute__ forwards the request to the server which handles it with a completely different environment. I'm thinking I have no business responding to this problem.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    3

    COM objects


    Printing or calling dir is not going to give you anything of use, you need the COM interface details (hopefully they are documented).

    I cannot find anything out about the COM object in question so the following is pure speculation.

    Normally the number of components value is defined at the same level as the collection you need to interface so I would normally expect something like:

    Code:
    for i in range(fluid.NumberofComponents):  
        print fluid.Composition(i).ComponentName

    Comments on this post

    • b49P23TIvg agrees : Thank you for confirming my inadequacy on this problem.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    These are our's custom libraries, so I have access to the code itself, not just the documentation. And this is the first time someone tried to use these classes from Python, we have samples written in C#, C++, Fortran, VB, Matlab and Java Script.
    Fluid object consists of Composition, PVTdata, FlowAssurance Data and few other. Composition consists of all the components names, molecular weights and so on.
    So, the Fluid object has only one Composition, and this code doesn't work.
    I can access all properties and methods that are not indexed (that are "single"). The code itself is written in C++ if that has anything to do with this.

IMN logo majestic logo threadwatch logo seochat tools logo