#define SWIG_PYTHON_2_UNICODE is notworking in python2,this is the file .i,PyUnicode_FromString can map std string to unicode
%include <std_pair.i>
%include <std_vector.i>
%include <std_string.i>
%template() std::pair<std::string,int>;
%template(PairVector) std::vector<std::pair<std::string,int> >;
%template(StringVector) std::vector<std::string>;
%begin %{
#define SWIG_PYTHON_2_UNICODE
%}
%{
#include "example.h"
%}
%typemap(out) std::string %{
$result = PyUnicode_FromString($1.c_str());
%}
%include "example.h"
How to convert a python2 unicode string to c++ std::string in swig?
wstring works