In addition to the answer from @jhoon, it looks like SWIG does not recognize the return type std :: string, so change the function to return const char *. Also, since this is a function outside the class, you cannot use self, but you must use the SWIG $ 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 invoking Python print on a 3x3 matrix.
If you find that you are adding this to many classes, consider packing in a macro, for example:
%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__() };
source share