win32com question

Jeff Shannon jeff at ccvcorp.com
Thu Jun 28 13:06:09 EDT 2001


Matthew Miller wrote:

> hi,
>
> i'm trying to figure out how to use the win32com interface. i haven't
> yet figured out how to 'phrase' optional arguments within a python
> expression. given something in vba like:-
>
> Workbooks.Open "spam.xls", ReadOnly:=true, Password:="password"
>
> how do you phrase this in python/win32. i got this far
>
> xlapp=win32com.client.Dispatch("Excel.Application")
> xlapp.Workbooks.Open("spam.xls")
>
> but can't figure out how to pass in the named args for the required
> functions .
> any help would be great.
> Thanks...

Use keyword arguments:

xlapp.Workbooks.Open("spam.xls", ReadOnly='True', Password='pass')

Note that, particularly the ReadOnly option, may use COM constants rather
than
the string "true", so you might need to use

from win32com.client import constants
xlapp.Workbooks.Open("spam.xls", ReadOnly=constants.True,
Password='pass')

Of course, you'll have to check your COM server's docs to find what uses
constants,
and constants are only available if you use early binding
(makepy/gencache)...

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list