[python-win32] How to add a record to a record list??
kbond
kbond at free.fr
Sat Aug 2 12:35:26 EDT 2003
Hello ,
Thank you for your tip but unfortunatly I am still stuck with my problem.
As you told me I ran MakePy on all the libraries some how related to
SMARTEAM including the SmRecList.
After few seconds the system told me that it had genrated a file
"C85E7012-8B4F-11D1-8E20-00A02498EA3Cx0x1x0.py"
I included in this mail some piece of this file if you need the file to
help me I can send it to you.
Until now I didn't manage to get it working I have the feeling that it
is just a problem of syntax.
you will find below the command I type in the interpreter the error
message and the function in the file generated by makepy.
I hope that I provide you all the information you need to help me else
please' do not hesitate to ask.
Thank you for your help
>>> recList.Value["FirstName",0] = "joe"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: object does not support item assignment
>>> recList.Value["FirstName",1] = "joe"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: object does not support item assignment
# The method SetValue is actually a property, but must be used
as a method to correctly pass the arguments
def SetValue(self, HeaderName=defaultNamedNotOptArg,
arg1=defaultUnnamedArg):
"""Retrieves, sets or adds a value to the object.
Specified by header name."""
return self._oleobj_.InvokeTypes(0, LCID, 4, (24, 0),
((8, 1), (12, 1)),HeaderName, arg1)
recList.SetValue("FirstName",0) ="joe"
Traceback (SyntaxError: can't assign to function call
>>> recList.SetValue["FirstName",0] ="joe"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File
"E:\users\install\Python23\lib\site-packages\win32com\client\dynamic.py",
line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: SmRecList.SmRecordList.SetValue
>>> recList.SetValue["FirstName",1] ="joe"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File
"E:\users\install\Python23\lib\site-packages\win32com\client\dynamic.py",
line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: SmRecList.SmRecordList.SetValue
# The method SetValueByIndex is actually a property, but must be
used as a method to correctly pass the arguments
def SetValueByIndex(self, HeaderIndex=defaultNamedNotOptArg,
arg1=defaultUnnamedArg):
"""Retrieves, sets or adds a value to the object.
Specified by header index."""
return self._oleobj_.InvokeTypes(2, LCID, 4, (24, 0),
((3, 1), (12, 1)),HeaderIndex, arg1)
>>> recList.SetValueByIndex("FirstName", 0) = "joe"
Traceback (SyntaxError: can't assign to function call
>>> recList.SetValueByIndex("FirstName", 0) = "joe"
Traceback (SyntaxError: can't assign to function call
>>> recList.SetValueByIndex["FirstName", 0] = "joe"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File
"E:\users\install\Python23\lib\site-packages\win32com\client\dynamic.py",
line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: SmRecList.SmRecordList.SetValueByIndex
# The method Value is actually a property, but must be used as a
method to correctly pass the arguments
def Value(self, HeaderName=defaultNamedNotOptArg):
"""Retrieves, sets or adds a value to the object.
Specified by header name."""
return self._ApplyTypes_(0, 2, (12, 10), ((8, 1),),
'Value', None,HeaderName)
>>> recList.Value["joe","FirstName"]
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: unsubscriptable object
>>> recList.Value["FirstName", "joe"]
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: unsubscriptable object
>>> recList.Value["FirstName", 0]= "joe"
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: object does not support item assignment
Jeff Shannon wrote:
> 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