importing win32com.client.Dispatch with embedded interpreter
Mike Haspert
mike_haspert at credence.com
Tue Jul 31 16:04:15 EDT 2001
Hi all:
The minimal function f1(), below in usecom.py, runs fine from the
command line, but when I use the C API for the interpreter, it runs
the first time and fails thereafter. Can anyone see what I'm doing
wrong? The error message "TypeError: this constructor takes no
arguments" has me stumped.
Thanks in advance for your help.
******************
#include "python.h"
#include <iostream>
int minimal(char* modname)
{
bool success = false;
PyObject *mod,*func,*args,*rvals;
Py_Initialize();
mod = PyImport_ImportModule(modname);
if(mod)
{
func = PyObject_GetAttrString(mod, "f1");
Py_DECREF(mod);
if(func)
{
if(NULL!= (args = Py_BuildValue("()")))
{
if(NULL!= (rvals = PyEval_CallObject(func,args)))
{
//use_the_rvals()
success = true;
Py_DECREF(rvals);
}
Py_DECREF(args);
}
Py_DECREF(func);
}
}
Py_Finalize();
return success;
}
int main(int argc, char* argv[])
{
cout<<"********first usecom\n"<<endl;
minimal("usecom");
cout<<"********second usecom\n"<<endl;
minimal("usecom");
cout<<"********end\n"<<endl;
return 0;
}
******usecom.py***********
def f1():
import traceback,string,sys
try:
from win32com.client import Dispatch
print "successful import of Dispatch"
except:
msg = string.join(traceback.format_exception(sys.exc_info()[0],
sys.exc_info()[1],sys.exc_info()[2]), "")
print str(msg)
if __name__ == "__main__":
print f1()
print f1()
**************the output***************
********first usecom
successful import of Dispatch
********second usecom
Traceback (most recent call last):
File "c:\scripts\usecom.py", line 4, in f1
from win32com.client import Dispatch
File "C:\Python21\win32com\__init__.py", line 95, in ?
SetupEnvironment()
TypeError: this constructor takes no arguments
********end
More information about the Python-list
mailing list