I followed
https://riptutorial.com/boost/example/25280/wrapping-std--vector-in-boost-python
but how to include vector_indexing_suite for passing vector as argument? I
am getting the error: No Python class registered for C++ class std::vector >
when running the code:

BOOST_PYTHON_MODULE(Strat)
{
    bp::class_<std::vector&lt;long> >("Long_vec")
        .def(bp::vector_indexing_suite<std::vector&lt;long> >())
    ;


    bp::class_<PyStrat, boost::noncopyable>("Strat")
        .def("gen_fibonacci", &Strat::gen_fibonacci)
        ;
}
int main() {
    try
    {
        Py_Initialize();
        // register the python module we created, so our script can import
it
        PyImport_AppendInittab("Strat",&initStrat);
        //PyImport_AppendInittab("StrategyFramework",
&initStrategyFramework);

        // import the __main__ module and obtain the globals dict
        bp::object main     = bp::import("__main__");
        bp::object globals  = main.attr("__dict__");

        // import our strategy.py file
        bp::object module   = import("Strat", "./python_plugins/strat1.py",
globals);

        // obtain the strategy class and instantiate one
        bp::object Strategy = module.attr("Strategy");
        bp::object strategy = Strategy();
        std::cout<<"not here";

        Helper a;
        strategy.attr("gen_fibonacci")(boost::ref(a.v),1,100);
        long ans=a.sum_series(a.v);
        std::cout<<"done";
        return 0;
    }
    catch(const bp::error_already_set&)
    {
        std::cerr << ">>> Error! Uncaught exception:\n";
        PyErr_Print();
        return 1;
    }
}

what am i doing wrong?

strat1.py:


    from Strat import *

    class Strategy:
        def gen_fibonacci(self,l,ind,n):
            num = 3
            t1 = 0 
            t2 = 1
            nextTerm = 0
            i=1
            if ind==1:
                l.append(0)
                l.append(1)
                i=3
            if ind==2:
                l.append(1)
                i=2
            while i<n:
                nextTerm=t1+t2
                t1=t2
                t2=nextTerm
                if num>=ind:
                    i=i+1
                    l.append(nextTerm)
                num=num+1
            return 0



--
Sent from: http://boost.2283326.n4.nabble.com/Python-c-sig-f2696818.html
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to