Problems instantiating class Boost Python class
Hi,
I'm a newbie having some problems instantiating a class written in C++
in Python using Boost.Python.
I can get a very simple example working when I expose a function outside
of a class, that returns a string, but the below fails as shown, despite
building. The enum in the same library however works fine.
I've googled the error returned from Python and I get zero hits - has
anyone get any idea what I'm doing wrong?
I'm using Python 2.5, GCC 4.0.1 and Boost 1.33 on Mac OS X 10.4.9. I
don't think it matters but I'm building the solution as a dynamic C++
bsd library in XCode and the changing the Mac OS X .dylib extention to
.so as is required by Python. This all works for simpler examples and
the enum in this example.
Error: TypeError: __init__() should return None, not 'NoneType'
Thanks,
Phil.
From header file example.h:
enum payOffType { CALL, PUT };
class Option
{
public:
//defaults to call
Option( double strike, double expiry );
double getPutCallMultiplier();
private:
double strike;
double expiry;
payOffType type;
};
From cpp file example.cpp:
Option::Option( double strike, double expiry ) : strike( strike ),
expiry( expiry ), type( CALL )
{
cout << "Option Contructor called";
}
double Option::getPutCallMultiplier()
{
return ( type == CALL ) ? 1 : -1;
}
BOOST_PYTHON_MODULE(libphil_boost)
{
class_<Option>("Option", init
import libphil_boost p = libphil_boost.Option( 23, 23 ) Option Contructor calledTraceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() should return None, not 'NoneType'
on Mon Jun 11 2007, Phil
Hi,
I'm a newbie having some problems instantiating a class written in C++ in Python using Boost.Python.
I can get a very simple example working when I expose a function outside of a class, that returns a string, but the below fails as shown, despite building. The enum in the same library however works fine.
I've googled the error returned from Python and I get zero hits - has anyone get any idea what I'm doing wrong?
I'm using Python 2.5, GCC 4.0.1 and Boost 1.33 on Mac OS X 10.4.9. I don't think it matters but I'm building the solution as a dynamic C++ bsd library in XCode and the changing the Mac OS X .dylib extention to .so as is required by Python. This all works for simpler examples and the enum in this example.
Error: TypeError: __init__() should return None, not 'NoneType'
Phil, First, I suggest you take your question to a more subject-specific mailing list: http://www.boost.org/more/mailing_lists.htm#cplussig I have no clue what could be going wrong here; I've never seen that problem. My only suggestion to you is to further reduce your test case to the absolute minimal example that reproduces the behavior. That almost always makes the problem obvious, or at least easily diagnosed. Your example is small, but surely not minimal yet. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
participants (2)
-
David Abrahams
-
Phil