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

kbond kbond at free.fr
Wed Jul 30 23:11:12 EDT 2003


Hello,

I am sorry for this long mail but I am completly stuck with the 
following problem I hope that someone will
be able to help me even if my problem is link to a propriatary software.

I am trying to translate into python some very basic VB script using an 
application called SMARTEAM.
I getting a pb to add a record to a record list.
I think I am missing something but I don't know what

here It is an extract of  the VB source script:

Sub Main()
  Dim RecList            As Object
  Dim SmRecord           As Object
  Dim SpecRecValArrays() As String
  Dim HeaderCnt          As Integer,i As Integer


  On Error GoTo ErrorTreat
'================================Creating an SmRecordList 
object===============================
  Set RecList = CreateObject("SmRecList.SmRecordList")

'================================Filling SmRecordList with headers and 
values===============================
 
  RecList.AddHeader "First Name",20,sdtchar
  RecList.AddHeader "Last Name",20,sdtchar
  RecList.AddHeader "ID",20,sdtchar
  RecList.AddHeader "Date of birth",8,sdtDate
 
  ' Adding first record Values
  RecList.Value("First Name",0) = "Joe"
  RecList.Value("Last Name",0) = "Smith"
  RecList.Value("ID",0) = "2145687-9"
  RecList.FormattedValueAsString("Date of birth",0,"dd/mm/yyyy") = 
"23/06/1968"        

  'Adding second record values
  RecList.Value("First Name",1) = "Sue"
  RecList.Value("Last Name",1) = "Ellen"
  RecList.Value("ID",1) = "7654980-7"
  RecList.FormattedValueAsString("Date of birth",1,"dd/mm/yyyy") = 
"12/10/1977"

the translation in python give me something like this:

import win32com.client

#===========================Creating an SmRecordList 
object=====================

recList=win32com.client.Dispatch("SmRecList.SmRecordList")

#================Filling SmRecordList with headers and 
values===================
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.

#==========================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)'''
###----2----
recList.Value("FirstName",1) = "joe"
'''exceptions.SyntaxError : can't assign to function call'''

###----3----
recList.Value("FirstName",1)[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 : object does not support item assignment'''
###----4----
recList.Value("FirstName",1)[1] = "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 : object does not support item assignment'''
###----5----
recList.Value("FirstName")[1] = "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 ?
  File "<COMObject SmRecList.SmRecordList>", line 2, in Value
  File 
"E:\users\install\Python23\lib\site-packages\win32com\client\dynamic.py", 
line 240, in _ApplyTypes_
    result = apply(self._oleobj_.InvokeTypes, (dispid, LCID, wFlags, 
retType, argTypes) + args)
'''pywintypes.com_error : (-2147352562, 'Invalid number of parameters.', 
None, None)'''
###----6----
recList.Value("FirstName",1)[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 : object does not support item assignment'''
###----7----
 >>> recList.Value("FirstName",0)[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 : object does not support item assignment'''
###----7----

.....

###----Added explanation----
recList.Value
<bound method CDispatch.Value of <COMObject SmRecList.SmRecordList>> 
 ###the method exist isn't it

Any suggestion are welcom I am running out of idea.
If you need more explanation do not hesitate to ask me.




More information about the Python-win32 mailing list