AW: How does one set a value via win32com
Stefan Migowsky
smigowsky at dspace.de
Wed Mar 28 03:18:28 EST 2001
Hi,
you ran on a problem with dynamic dispatch. It can't use properties
with parameters. In a makepy generated wrapper properties with parameters
are translated in methods. So you must use a wrapper to use such parameters.
To ensure a wrapper use the gencache module, in your case
import win32com.client
import regex
wcc = win32com.client
# Ensure that a makepy generated wrapper is available
wcc.gencache.EnsureDispatch("COMAdmin.COMAdminCatalog")
adm = wcc.Dispatch( "COMAdmin.COMAdminCatalog" )
app = adm.GetCollection("Applications")
app.Populate()
for thingy in app:
if regex.match("^Hello World.*",thingy.Name)!= -1:
print "what we have here is ...",thingy.Name
# Use generated method which is not available dynamically
# since the COM object does not export SetValue
thingy.SetValue("Name", thingy.Name + "t0")
print thingy.Value("Name")
break
else:
print thingy.Name
app.SaveChanges()
Stefan
> -----Ursprüngliche Nachricht-----
> Von: Richard Weth [mailto:richard at loudcloud.com]
> Gesendet: Dienstag, 27. März 2001 21:24
> An: python-list at python.org
> Betreff: How does one set a value via win32com
>
>
> All
>
> I have been banging away on an assignment that requires me to
> alter com
> plus settings
> (something one should never do normally). Here is the pertinent code
> fragment:
> import win32com.client
> import regex
> wcc = win32com.client
>
> adm = wcc.Dispatch( "COMAdmin.COMAdminCatalog" )
> app = adm.GetCollection("Applications")
> app.Populate()
>
> for thingy in app:
> if regex.match("^Hello World.*",thingy.Name)!= -1:
> print "what we have here is ...",thingy.Name
> thingy.Value("Name") = thingy.Name + "t0" #
> <================ THE PROBLEM
> break
>
> else:
> print thingy.Name
> app.SaveChanges()
>
>
> Now the code in VBS
> thingy.Value("Name") = thingy.Name & "t0"
> works just fine but in python I get:
> >>> thingy.Value("Name") = "joemama"
> SyntaxError: can't assign to function call
>
> Is there a way to set that (and other) properties in Python via
> win32com. I really
> would like to learn as little VB as humanly possible and not
> write this
> in it's own VBScript.
> Any and all suggestions welcome!
>
> --
> Sincerely
> Richard A. Weth
> Sr. Software Engineer
> LoudCloud, Inc
> richard at loudcloud.com
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list