ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
Re: [C++-sig] Can I import a module in C++ and use in python script ?
by Pierre Barbier de Reuille other posts by this author
Oct 20 2003 8:35AM messages near this date
[C++-sig] Can I import a module in C++ and use in python script ? | [C++-sig] Re: RTTI and image size
Le lun 20/10/2003 à 17:16, Atul Kshirsagar a écrit :
>  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

You have to call the module init function once python is started. In
your case it should be :

initFlPythonModulesud()

Then you can call the "from FlPythonModulesud import *" using
PyRun_String ! (At least that's what I do and it workd well)

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 


_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Atul Kshirsagar
Pierre Barbier de Reuille

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved