I have something like the following:
swigtest.cpp
#include <string>
class Foo {
public:
std::string bar() {
return "baz";
}
};
inline Foo* new_foo() {
return new Foo;
}
swigtest.i
%module swigtest
%{
#include "swigtest.hpp"
%}
%include <std_string.i>
%include "swigtest.hpp"
%newobject new_foo;
useswig.py
from swigtest import new_foo
foo = new_foo()
print(foo.bar())
print(type(foo.bar()))
$ swig -c++ -python -modern swigtest.i $ g++ -fpic -shared -I/usr/include/python2.7 -DSWIG_PYTHON_2_UNICODE swigtest_wrap.cxx -lpython2.7 -o _swigtest.so $ python2 useswig.py baz <type 'str'>
Is there any way to get that to output
<type 'unicode'>
instead? I understand from the docs that
When the SWIG_PYTHON_2_UNICODE macro is added to the generated code ... Unicode strings will be successfully accepted and converted from UTF-8, but note that they are returned as a normal Python 2 string
Is there a way to achieve that, possibly with a custom typemap somehow?