Swig/Python: data type problem
Lyle Johnson
ljohnson at resgen.com
Tue Apr 2 09:27:24 EST 2002
> But in C++, we expect a data type:
>
> void MyObject::read(String* namefile)
>
> I tryed with 3 data types: char / string / string*
> Each time, I have the same error:
>
> File "c:\python21\Module1.py", line 172, in read
> val = apply(Interfc.RoadNetwork_lecture,args)
> TypeError: Type error. Expected _p_String
>
> Do you have any suggestion?
Well, the short answer is that you need to specify a typemap for String
pointers in your SWIG interface file. Since I'm not familiar with your
library's String class, let's just assume that the String class has a
constructor that takes a const char * for the string's contents. In that
case you could write an "in" typemap:
%typemap(in) String * {
$1 = new String(PyString_AsString($input));
}
For more details, please read the SWIG user manual (especially the stuff
about typemaps).
Hope this helps,
Lyle
More information about the Python-list
mailing list