Swig/Python: data type problem
Lyle Johnson
ljohnson at resgen.com
Wed Apr 3 10:05:57 EST 2002
> Thank you for your answer.
> I have read the swig documentation, but I have still some more questions:
>
> - where I have to put the code:
> %typemap(in) String * {
> $1 = new String(PyString_AsString($input));
> }
> in the .i file?
This typemap needs to appear somewhere in your SWIG interface file before
the declaration of your "void read(String *namefile)", so that by the time
SWIG processes the function declaration it knows about the typemap.
> - what is $1 and $input ? They are not recognized...
Which version of SWIG are you using? I was writing it using SWIG 1.3
conventions. If you are instead using SWIG 1.1, try this typemap instead:
%typemap(python, in) String * {
$target = new String(PyString_AsString($source));
}
> - is it the only piece of code I must write to solve my data type problem?
> for instance, do I have to write something in the read function?
Adding this typemap should solve the problem of converting a Python string
input argument to one of your library's String objects before calling
read(). Since I have absolutely no other information about your library's
code I can't speculate on what other problems might come up.
More information about the Python-list
mailing list