3

I would like to know how to use python to make calls to a C++ library called libwpd to read word perfect files and build python objects from them, but I have no experience with C++ or calling C++ functions from python, and I don't understand how to figure out what the output of these library functions would be. So that's really two questions:

  • 1) how to call C++ functions from python, and
  • 2) how to figure out what the output of these functions would be--namely, the result of the WPDocument::parse function (see http://www.abisource.com/~uwog/libwpd/) and how to use it in my python code. The function appears to return an object WPDResult, but I can't figure out what it does or how I would use it.
I looked into SWIG briefly, and it looks promising. Thoughts?
twneale
  • 2,836
  • 4
  • 29
  • 34

2 Answers2

2

Checkout ctypes. It's part of the standard Python library set. I can't speak to it's use with C++, but I suspect it will work nicely.

Peter Rowell
  • 17,605
  • 2
  • 49
  • 65
  • 2
    C++ has no standard binary interface, so ctypes is not guaranteed to work. For calling functions in C binaries it is very nice indeed. – Roberto Bonvallet Dec 28 '09 at 03:27
2

The Boost.Python library allows easy interoperability between C++ and Python.

The tutorial shows how to wrap C++ functions and classes to use them from Python.

Roberto Bonvallet
  • 31,943
  • 5
  • 40
  • 57