I have 2 questions, both relating to how arguments between Python and C++ mix… I have a function in C++ which I am calling from python, and my function takes dates and strings.
Is a python str the same as a C++
class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >
And secondly, my function needs a date of type class boost::gregorian::date, does anyone know how I can give a date in python that will be read with the correct signature?
Help much appreciated! I hope this is a fairly simple problem, I’m just not very experienced with different types of signatures (which doesn’t bode well for my current experimentation into linking Python and C++)!
Assuming that you are using
boost::python, let me give you an idea of how to proceed in these cases. Rather than lettingboost::pythonautomatically wrap your function, you provide your own wrapping:Of course you need to provide a method that converts a
boost::python::objectinto aboost::gregorian::dateobject. You have to decide how to handle this. For instance, you could assume that the parameter is a sequence of three integers, or you could allow more complex way of passing the parameters, or define a new class that wraps the gregorian date and all of its method and exposes it directly to Python.As for your first question, when using
boost::pythonstd::strings are automatically converted to/from Python strings.