[C++-sig] Instantiating class_<> objects without use of aninterpreter? - Bayesian Filter detected spam

AJ Frantz ajfrantz at umich.edu
Wed Feb 21 15:21:34 CET 2007


Your "attention" notes at the bottom are all good policies, to be
sure.  However, I've tried placing the class_<> definitions in many
places, as well as replicating it throughout the code, thinking that
was somehow involved.

I think I was closer with my initial assessment: the problem is the
Python interpreter is not initialized.  If you use my code from my
original posting, but simply add a call to Py_Initialize() to the
beginning of main(), everything seems to work, no errors...

I'm not sure why it took me this long to try that.  Does anyone see
problems with this method?  I'll probably be embedding Python at some
point so it is perhaps not the worst alternative.

AJ


On 2/21/07, Podpruzhnikov Yuri <ypodpruzhnikov at mcode.ru> wrote:
> My decision of this problem is (it may be is not best):
>
>
> 1)Declare all class_<>  only in module definition
> (BOOST_PYTHON_MODULE(DataTypes){...}):
> BOOST_PYTHON_MODULE(DataTypes)
> {
>         class_<OneDataType>("OneDataType", init<int>())
>                         .def("someFunc", &OneDataType::someFunc);
>
>         class_<SomeFactoryClass, boost::noncopyable>("SomeFactoryClass",
> no_init);
>
>         class_<OneFactory, bases<SomeFactoryClass> >("OneFactory")
>                         .def("makeSomething",
> &OneFactory::makeSomething);
> }
>
> 2) Write this in all factories next code:
> object OneFactory::makeSomething()
> {
>         return object(OneDataType(42));
> }
>
>
>
> ATTENTION:
> Definition of class_<OneDataType> always must be before create
> object(OneDataType(42))
>
> If class_<OneDataType> and function, which create
> object(OneDataType(42)), declared in one module - all right
> But its declared in different modules -
>         module contain class_<OneDataType>     must be imported before
> module contain function, which create object(OneDataType(42))
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>



More information about the Cplusplus-sig mailing list