Passing an object from VB using Microsoft's Script Control to python
Max Barry
max at ford-consulting.com
Thu May 29 17:39:50 EDT 2003
I am trying to run Python using Microsoft's Script Control in VB and when I
pass a Scripting.Dictionary as an object, I cannot access Items(), Count()
or Keys(). I can't even get to a item using its key value. The following
error is displayed when trying to access the dictionary:
Unexpected Python Error: pywintypes.com_error:(-2147467263, 'Not
implemented', None, None)(Python COM Server Internal Error)
I have added some sample code below:
VB6 Code:
Dim mydic as Object
Set mydic = CreateObject("Scripting.Dictionary")
'fill with some values.
For i = 1 To 10
mydic.Add "item" & i, "object " & i
Next
Set mSct = New ScriptControl
mSct.Language = "Python"
mSct.Timeout = 20000 ' 20 seconds
'This is where the dictionary that gets passed to the python script
mSct.AddObject "mdict", mydic
With fso.OpenTextFile("dicttest.py")
mSct.AddCode .ReadAll
End With
mSct.CodeObject.Initialize
Set mSct = Nothing
Python code (dictest.py):
def Initialize():
import pywintypes
from tempfile import gettempdir
import os import path
outfilename = "testcontrol.txt"
outfilepath = path.join(gettempdir(), outfilename)
filout = open(outfilepath, 'w+')
filout.write("THIS IS A TEST FILE FOR SCRIPT CONTROL\n")
filout.write ("Dictionary Count: " + mdict.count) # write dictionary
count to testcontrol.txt in temp directory.
filout.close
#END OF SAMPLE
Any ideas on how I can make this work?
More information about the Python-list
mailing list