1

I have heterogeneous list of int and string I want to store all of them in vector<string>. With this command:

    std::string temp = boost::python::extract<std::string>(xList[i][j]);

I get this error:

TypeError: No registered converter was able to produce a C++ rvalue of type std::string from this Python object of type float

1 Answer 1

2

You have two choices: either get the values as boost::python::object and check the types and do whatever you like, or register a converter that turns numbers into strings (using std::to_string presumably).

You can use the instructions for "Extracting C++ Types" in the docs:

extract<std::string&> extractor(xList[i][j]);
if (extractor.check()) {
    std::string& v = extractor();
2
  • Thanks, how can I get it as boost::python::object and check the types? Nov 14, 2014 at 1:55
  • Why the string is defined as reference? Nov 14, 2014 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.