on Thu Nov 13 2008, Stefan Seefeld <seefeld-AT-sympatico.ca> wrote: > Alan Baljeu wrote: >> >> As best I could figure, I needed to write Python code, execute a script >> file, get >> that code to call a C function that I register, in order to have that >> function. At >> least the tutorial implied that was the way. > > I'm confused. In your last mail you asked for how to get hold of a Python > function so > you could run it from within C++. Now you want to run a C function instead ? > > Python is an interpreted language, so you need to read (interpret) the code > that you > then want to run. I asked where the function that you want to store and run > comes > from. If it already exists in a module, you can simply import that module > (using > boost::python::import()), and extract the function from it: > > object module = import("your_module"); > object function = module["your_function"];
object function = module.attr("your_function"); right? > function(); // call it > > If you don't want to import a module directly, but rather run a script, use > exec() > instead. > > I'm not sure how this could be any simpler. :-) -- Dave Abrahams BoostPro Computing http://www.boostpro.com _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig