I was reading Chapter 12 of Python Programming on Win32 and trying to mimic the sample code DynamicPolicy.py. I wanted to expose methods/properties defined in the module os. Here is what I did. I only made very minor changes to the original code. It seems the COM server was registered. At least there was no error message. But when I tried testing it with VBA, nothing worked.
Python code:
# DynamicPolicy.py -- A demonstration of dynamic policies in PythonCOM
import os
import pythoncom
import pywintypes
import winerror
import types
from win32com.server.exception import COMException
def FixArgs(args):
( I maded no change to this funtion)
class PythonModuleOs:
_reg_progid_ = "pymodule.os"
_reg_clsid_ = "{67C9267A-55EE-4B17-A556-4FA34F42EE3F}"
_reg_policy_spec_ = "DynamicPolicy"
def _dynamic_(self, name, lcid, wFlags, args):
the only change i made with this function is I changed
try:
item = getattr(string, string.lower(name))
to
try:
item = getattr(os, os.listdir(name))
VBA code for testing:
Public Sub TestCOMServer()
Dim pym As Variant
Set pym = CreateObject(" pymodule.os")
MsgBox pym.listdir("C:\Temp")
End Sub
I got an error message:
"No such file or directory: 'listdir'
Can someone show me what needs to be done in order to create a COM server to expose other python modules? Btw, I didn't copy & post the original code because I'm not sure if it is ok to do so.
Thank you.
Regards,
- wcc
_______________________________________________ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
