Problem with VB-COM-Python arg passing/value returning

Sue Giller sag at hydrosphere.com
Thu Mar 7 17:45:17 EST 2002


I am hoping that someone here can help me with the following 
problem.

I have an application that uses a VB 6 front end and python 
backend.  The VB app creates some python COM objects and calls 
those objects to get python to do the work.  The VB just displays 
results, etc.  This is on W2000, SP2, python is
'2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)]'

In one case, I am passing a VB class object to the python COM 
object. This contains a set of complicated configuration settings for 
a python object to use when it does its thing.  In that VB class 
object, there are some functions that allow python to obtain data 
stored in that class object.

If the function in the VB class does not have any input args, then the 
return from that function to python is correct.

However, if the VB class does have input args, then the values of 
those args are appended to the end of the return values.  If I change 
the value of the input args, that changed value is reflected in the 
returned data.  If I use 'Byval' for the arg, I get a python error "List() 
args must be a sequence"

Can anyone explain what is going on here?  Is this a bug?  Can I 
assume that I can discard the trailing items in ALL cases where I 
pass an arg(s) to such a function?

VB pseudo code, python pseudo code, very simplified

VBclass					           'class with function being used
public property get NeedsArg(arg1) as variant
	NeedsArg = 1					' should return a single item
end property						' all type returns have the problem
public property get NoArgs() as variant
	NoArgs = 1
end property
public property get ByValArg(byval arg1) as variant
	ByValArg = 1
end property

'create the python com object that uses the vb class
pythonObject = CreateObject("python.comthing")
'create the class instance to be passed
vbObject = new VBClass
'pass object to python
pythonObject.UseMe(vbObject)					

python class						# python class set up as COM
_public_methods_ = [ 'UseMe' ]
_reg_progid_ = "python.comthing"
 _reg_clsid_ = blah blah blah

def UseMe(vbObject):
	idobj = win32com.client.Dispatch(vbObject)
	info = idobj.NeedsArg("abc")
	print `info`						# prints out (1,'abc')
	info = idobj.NoArgs()
	print `info`						# prints out (1) as it should
	info = idobj.ByValArg("abc")	# raises python error:  
									#Type Error:  list () argument 
must be a sequence
	print `info`




More information about the Python-list mailing list