boost-python

Wrapping a pure virtual method with multiple arguments with Boost.Python

Hello, I followed the "official" tutorial and others but still don't manage to expose this pure virtual method (getPeptide) : ms_mascotresults.hpp class ms_mascotresults { public: ms_mascotresults(ms_mascotresfile &resfile, const unsigned int flags, double ...

Boost Python : How to only expose the constructor of a class with virtual (pure & impure) methods

Hello, I'm a newbie with Boost::Python but I tried to search on the web to do so I want to expose a 3rd party library to Python. One of the class of the library (.hpp) is composed of a public constructor with arguments a protected constructor and functions various regular functions various pure virtual functions various non pure virt...

How can I get the Python module and line number that called my C++ function via Boost::Python?

I have a C++ function that is being called from many Python functions via Boost::Python. When the C++ function detects bad arguments I want to write a log message and continue processing. In that log message I would like to note the Python module and line number that called into C++. How can I do this? I am able to throw an exception fr...

boost::python string-convertible properties

I have a C++ class, which has the following methods: class Bar { ... const Foo& getFoo() const; void setFoo(const Foo&); }; where class Foo is convertible to std::string (it has an implicit constructor from std::string and an std::string cast operator). I define a Boost.Python wrapper class, which, among other things, defines...

make_tuple with boost::python under Visual Studio 9

Trying to build the following simple example #include <boost/python.hpp> using namespace boost::python; tuple head_and_tail(object sequence) { return make_tuple(sequence[0],sequence[-1]); } available here, I end up with this compilation error under Visual Studio 9 error C2668: 'boost::python::make_tuple' : ambiguous call to over...

How to add a property to a module in boost::python?

You can add a property to a class using a getter and a setter (in a simplistic case): class<X>("X") .add_property("foo", &X::get_foo, &X::set_foo); So then you can use it from python like this: >>> x = mymodule.X() >>> x.foo = 'aaa' >>> x.foo 'aaa' But how to add a property to a module itself (not a class)? There is scope().a...

Boost.Python wrapping hierarchies avoiding diamond inheritance

I'm having some trouble seeing what the best way to wrap a series of classes with Boost.Python while avoiding messy inheritance problems. Say I have the classes A, B, and C with the following structure: struct A { virtual void foo(); virtual void bar(); virtual void baz(); }; struct B : public A { virtual void quux(); }...

Reinterpret a CGImageRef using PyObjC in Python

Hi, I'm doing something that's a little complicated to sum up in the title, so please bear with me. I'm writing a Python module that provides an interface to my C++ library, which provides some specialized image manipulation functionality. It would be most convenient to be able to access image buffers as CGImageRefs from Python, so they...

Explain Python extensions multithreading

Python interpreter has a Global Interpreter Lock, and it is my understanding that extensions must acquire it in a multi-threaded environment. But Boost.Python HOWTO page says the extension function must release the GIL and reacquire it on exit. I want to resist temptation to guess here, so I would like to know what should be GIL locking...

Build problems when adding `__str__` method to Boost Python C++ class

I have started to play around with boost python a bit and ran into a problem. I tried to expose a C++ class to python which posed no problems. But I can't seem to manage to implement the __str__ functionality for the class without getting build errors I don't understand. I'm using boost 1_42 prebuild by boostpro. I build the library usi...

Boost.Python tutorial in Ubuntu 10.04

I downloaded the latest version of Boost and I'm trying to get the Boost.python tutorial up and running on Ubuntu 10.04: http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/hello.html I navigated to the correct directory, ran "bjam" and it compiled using default settings. I did not yet create a bjam config file...

How to link to existing boost python module

I have wondered about this on and off but I never really got a definite answer. Is it possible within the boost.python framework to link against another boost.python module. For example I have exported class A within boost_python_module(libA) and function B(A a) within boost_python_module(libB). Is it possible to specify in libB to lin...

Boost.Python on Mac OS X: "TypeError: Attribute name must be string"

Hello all, I recently installed Boost using MacPorts, with the intent to do some Python embedding in C++. I then decided to check if I configured Xcode correctly with an example found on Python's website: #include <boost/python.hpp> using namespace boost::python; int main( int argc, char ** argv ) { try { Py_Initial...

PyV8 Install Problems (Cannot find boost)

I am attempting to install PyV8 (http://code.google.com/p/pyv8/) using: python setup.py install However, the build fails with the following: louis@louis-desktop:~/Downloads/PyV8-0.9$ python setup.py install running install running build running build_py running build_ext building '_PyV8' extension gcc -pthread -fno-strict-aliasing -D...

How do I ensure that the same Python instance is always returned for a particular C++ instance?

I'm using Boost.Python to wrap a C++ library. How do I ensure that the same Python instance (by object identity) is always returned for a particular C++ instance (by pointer identity)? I can't extend the C++ classes, but I can add a member variable (such as a PyObject * or a boost::python::handle<>) if that helps. I'm thinking that I sh...

Problems regarding Boost::Python and Boost::Threads.

Me and a friend are developing an application which uses Boost::Python. I have defined an interface in C++ (well a pure virtual class), exposed through Boost::Python to the users, who have to inherit from it and create a class, which the application takes and uses for some callback mechanism. Everything that far goes pretty well. Now, t...

Pickling an enum exposed by Boost.Python

Is it possible to pickle (using cPickle) an enum that has been exposed with Boost.Python? I have successfully pickled other objects using the first method described here, but none of that seems to apply for an enum type, and the objects don't seem to be pickleable by default. ...

does boost python support a function returning a vector, by ref or value?

I am new to python, I have looked at boost python, and it looks very impressive. However going through the introduction I can not find any examples where, vector of objects are returned as python list/tuples. i.e Take this example, I want to expose class X, Cont and all its functions. critical bit being return a vector of X's or st...

passing C++ classes instances to python with boost::python

I have a library which creates objects (instances of class A) and pass them to a python program which should be able to call their methods. Basically I have C++ class instances and I want to use them from python. Occasionally that object should be passed back to C++ for some manipulations. I created the following wrapper file (let's as...

Creating a C wrapper with Cython - Python

Hi folks, I've been trying to figure out how to wrap the following C functions = compress.c , compress.h. I tried following the tutorials, but after creating the .pxd file I don't know what to do :| From what I have understood this is the pxd file that I should have cdef extern from "compress.h": size_t compress(void *s_start, v...