[python-win32] How to add a record to a record list??

Jeff Shannon jeff at ccvcorp.com
Wed Jul 30 15:31:13 EDT 2003


kbond wrote:

> import win32com.client
>
> recList=win32com.client.Dispatch("SmRecList.SmRecordList")
>
> recList.AddHeader("FirstName", 20, 1)   #####my fist problem I do not 
> understand why
> recList.AddHeader ("Last Name",20,1)   ####I cannot give name of the 
> Standard Data
> recList.AddHeader ("ID",20,7)                      ####Type but I Have 
> to give the rank of this data type in the enum. 


This is because PythonCom cannot automatically get information from a 
type library, as VB does.  You need to run MakePy on your type library 
(from PythonWin, select "COM MakePy Utility" from the Tools menu, then 
find the type library for SmRecList).  Once you've done that, then 
PythonCom should understand the constants and enums that are used by the 
COM object.  (MakePy will create a set of Python files in its own 
subdirectory that will then automatically translate for methods that 
access that COM object.)  There's other subtle benefits to using MakePy, 
so I'd strongly recommend doing so any time you have a type library 
available (which should be the case for many, if not most, commercial 
COM objects).

> #==========================Adding first record 
> Values===========================
> #Here is my major problem I cannot a valu to the first Record
> #Till now I have tried the following syntaxe but none of them was ok
> ###----1----
> recList.Value("FirstName",0,"joe")
>  File 
> "E:\users\install\Python23\Lib\site-packages\wxPython\tools\boa\ExternalLib\PythonInterpreter.py", 
> line 69, in push
>    exec code in self.locals
>  File "<console>", line 1, in ?
> '''exceptions.TypeError : Value() takes at most 3 arguments (4 given)''' 


It looks like VB is treating Value as a property, rather than as a 
straightforward attribute or method.  Python doesn't have properties as 
such.  (Well, new versions of Python are introducing properties on 
new-style classes, but all of this is much more recent than the 
PythonCom apparatus, so it's beside the point here.)  In order for 
Python to properly simulate properties and things like in/out 
parameters, it needs to know the type and purpose of arguments.  This is 
one of the things that MakePy does.  So, I *think* that if you run 
MakePy, this example will work.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-win32 mailing list