When python extension is generated by swig, the following `` repr``` is automatically defined in the structure defined in C.
<swig_mymodule.mytype; proxy of <Swig Object of type 'struct mytype *' at 0x7f6c74210a20> >
I'd like to do something because it's not cool as it is, but I couldn't find a way to control it on the C side (or rather, with swig).
If you do setattr
in% python code
as shown below, the contents will be output in the python code generated by swig, so it will be overwritten at the time of import.
swig_mymodule.i
%pythoncode %{
import types
def __mytype_str(self):
return "<Mytype(…)>”
setattr(mytype, '__str__', types.MethodType(__mytype_str, None, mytype))
%}
Recommended Posts