[python-win32] Works in VB, not in Python?

Boingo oboingo at gmail.com
Fri Mar 9 19:08:57 CET 2007


Hello there,

I am a bit new to PyWin32, but not new to Python.  I am new to the COM
object I am trying to work with though.  I have code that works in VB
to access a COM object, but similar code in Python is not working.  I
am pretty sure I am doing something wrong.  Any help would be greatly
appreciated.  The VB code is:

----------------------------------------------------
Set oScript = CreateObject ("ProvideX.Script")
oScript.Init("C:\\Program Files\\Sage Software\\MAS 90\\Version4\\MAS90\\Home")

' Set the user for the Session
Set oSS = oScript.NewObject("SY_Session")
r = oSS.nLogon()
If r=0 Then
    ' Please remember to replace the usercode, password with valid info
    r = oss.nSetUser("xxx","xxx")
End If
-----------------------------------------------------

There is more code then that, but I can't even get that far in the
Python code.  The Python so far is:

-----------------------------------------------------
>>> import win32com.client
>>> oScript = win32com.client.Dispatch("ProvideX.Script")
>>> oScript
<win32com.gen_py.ProvideX OLE Server Library.IScript instance at 0x18439184>
>>> oScript.Init("C:\\Program Files\\Sage Software\\MAS
90\\Version4\\MAS90\\Home")
>>> dir(oScript)
['AddNamedObject', 'CLSID', 'DeleteNamedObject', 'Evaluate',
'Execute', 'Init', 'NewObject', 'Parameter', 'Reset', 'Run',
'SetParameter', '_ApplyTypes_', '__cmp__', '__doc__', '__getattr__',
'__init__', '__module__', '__repr__', '__setattr__',
'_get_good_object_', '_get_good_single_object_', '_oleobj_',
'_prop_map_get_', '_prop_map_put_', 'coclass_clsid']
>>> oSS = oScript.NewObject("SY_Session")
>>> oSS
<win32com.gen_py.ProvideX OLE Server Library.IPvxDispatch instance at
0x18581224>
>>> dir(oSS)
['CLSID', 'DropObject', '_ApplyTypes_', '__cmp__', '__doc__',
'__getattr__', '__init__', '__module__', '__repr__', '__setattr__',
'_get_good_object_', '_get_good_single_object_', '_oleobj_',
'_prop_map_get_', '_prop_map_put_', 'coclass_clsid']
>>> login = oSS.nLogon()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
line 454, in __getattr__
    raise AttributeError, "'%s' object has no attribute '%s'" %
(repr(self), attr)
AttributeError: '<win32com.gen_py.ProvideX OLE Server
Library.IPvxDispatch instance at 0x18581224>' object has no attribute
'nLogon'
>>> l = oSS.SetUser("xxx","xxx")
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
line 454, in __getattr__
    raise AttributeError, "'%s' object has no attribute '%s'" %
(repr(self), attr)
AttributeError: '<win32com.gen_py.ProvideX OLE Server
Library.IPvxDispatch instance at 0x18581224>' object has no attribute
'SetUser'
---------------------------------------

Even though the dir(oSS) command shows that list, when I type oSS. in
the interactive window, the popup of options lists more options, as
does the COM browser.  When I try these options in the interactive
window, I get the same as above... "object has no attribute".  What is
VB doing that Python isnt?  Any help that anyone could give would be
greatly appreciated.

Thank you in advance for any help you can provide.


More information about the Python-win32 mailing list