[C++-sig] Can I import a module in C++ and use in python script ?

Atul Kshirsagar atulkshirsagar at yahoo.com
Mon Oct 20 17:16:05 CEST 2003


I have following code in my C++ application using
python extension module "FlPythonModulesud".

Py_Initialize();
PyObject *m, *d, *m2;
m = PyImport_AddModule ("__main__");
d = PyModule_GetDict (m);
m2 = PyImport_ImportModuleEx ("FlPythonModulesud", d,
d, NULL);
PyDict_SetItemString (d, "FlPythonModulesud", m2);


I use python in multithreaded environment. I have
embedded a few C++ classes within pthon using Swig. I
run python expressions using PyRun_String().

A sample python expression looks like this;

from FlPythonModulesud import *

# Get collection pointer
collection = FlDataCollectionPtr(Collection)
# get collection size (num records in collection)
numRecords = collection.size()
print numRecords

Here FlDataCollectionPtr is a embedded class pointer
and Collection is a variable passed to python.

What I am trying to do is get rid OFF statement 
from FlPythonModulesud import * 
in the script programatically.

But the above PyImport_ImportModuleEx() doesn't serve
my purpose.

Any help will be appreciated !!!
Atul



__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com




More information about the Cplusplus-sig mailing list