I am using swig wrapper of openbabel (written in C++, and supply a python wrapper through swig)
Below i just use it to read a molecule structure file and get the unit
Further to the answer from @jhoon, it seems that SWIG doesn't recognise the std::string return type so change the function to return const char*. Also, since it is a function outside the class, you can't use self but you must use SWIG's $self variable.
So, in the SWIG .i file, if you put the following:
%extend OpenBabel::matrix3x3 {
const char* __str__() {
std::ostringstream out;
out << *$self;
return out.str().c_str();
}
};
you should get the desired result when calling Python's print on a matrix3x3.
If you find yourself adding this to many classes, consider wrapping it in a macro like:
%define __STR__()
const char* __str__() {
std::ostringstream out;
out << *$self;
return out.str().c_str();
}
%enddef
and then adding it to the class with:
%extend OpenBabel::matrix3x3 {
__STR__()
};