Dennis Chung wrote:
> I am running this code on the python shell the test was loaded
> successfully.  I will illustrate my problem more clearly.  I currently
> have a work around by explicitly passing "self" but I'd like to better
> understand the issue.  As you can probably tell, I am new to python.
>
> The following code allows me to successfully run a test:
> ---
> import win32com.client
> o = win32com.client.Dispatch("QuickTest.Application")
> o.Launch()
>
> # i've escaped the \ this time but it also worked the first time
> o.Open("C:\\Documents and Settings\\DChung\\Desktop\\XMLRequest")
> o.Visible = True
> o.Test.Run(o.Test) # this works fine, o.Test.Run() does not.
> ---
>
> Using "o.Test.Run()" I get the following:
> Traceback (most recent call last):
>   File "<pyshell#11>", line 1, in <module>
>     o.Test.Run()
>   File
> "C:\Python31\lib\site-packages\win32com\gen_py\5BF80934-AEDA-4463-B199-B83285266562x0x1x0.py",
> line 1717, in Run
>     , WaitOnReturn, Parameters)
> TypeError: The Python instance can not be converted to a COM object
>
> According to the documentation I should be able to invoke Run() with
> no parameters (See below).  I have explicitly passed "self" to the Run
> method otherwise I run into the above problem.  When invoking other
> methods from this library, i.e. Launch() and Open(), I do not need to
> pass "self".

Yes, but there's a big difference between those.  With Launch and Open,
you are working with the "o" object.  But with o.Test.Run(), you aren't
working with "o", you are working with whatever object is returned from
the Test property of "o".  That's a brand new object of a different
type, and I'm guessing that's where the problem lies.

Try printing o.Test to see what you get.  Then, try:
    tst = o.Test
    tst.Run()


> Could it be a problem with the COM object?  Why do I need to
> explicitly pass a reference to "self" when calling Run (or any other
> Test object method for that matter)?

You should not need to.  Self is always passed as the first parameter in
any method invocation.  It is interesting that the property has the same
name as the class itself.  That's a little disconcerting.  For example,
**IF** o.Test were mapping to the class instead of being a property that
returned an object, you might see the results you are seeing.

-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to