Rolf Wester | 5 May 2004 09:09
Picon
Favicon

How to use a C++ std::string from Python

Hi,

a have a C++ module with functions that have std::string parameters. The 
build works fine but
I don't know how to call such a method. When using a Python string as 
function parameter I get
an error message:

>>> im.read_bmp_file("dvac001.bmp",0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "image.py", line 423, in read_bmp_file
    def read_bmp_file(*args): return _image.Image_read_bmp_file(*args)
TypeError: Type error. Got dvac001.bmp, expected _p_std__string

How can I call this function from Python? I would be very appreciative 
for any help.

With kind regards

Rolf Wester

_______________________________________________
Swig maillist  -  Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Marcelo Matus | 5 May 2004 23:39
Picon

Re: How to use a C++ std::string from Python

Sorry!!!, is not importing, you need to include the string file

%include std_string.i

Marcelo

Rolf Wester wrote:

> Hi,
>
> a have a C++ module with functions that have std::string parameters. 
> The build works fine but
> I don't know how to call such a method. When using a Python string as 
> function parameter I get
> an error message:
>
>>>> im.read_bmp_file("dvac001.bmp",0)
>>>
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "image.py", line 423, in read_bmp_file
>    def read_bmp_file(*args): return _image.Image_read_bmp_file(*args)
> TypeError: Type error. Got dvac001.bmp, expected _p_std__string
>
> How can I call this function from Python? I would be very appreciative 
> for any help.
>
> With kind regards
>
> Rolf Wester
(Continue reading)

Marcelo Matus | 5 May 2004 23:38
Picon

Re: How to use a C++ std::string from Python

Did you import the std_string.i library file?

If not, you need to add the following line to your swig interface file

%import std_string.i

Marcelo

Rolf Wester wrote:

> Hi,
>
> a have a C++ module with functions that have std::string parameters. 
> The build works fine but
> I don't know how to call such a method. When using a Python string as 
> function parameter I get
> an error message:
>
>>>> im.read_bmp_file("dvac001.bmp",0)
>>>
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "image.py", line 423, in read_bmp_file
>    def read_bmp_file(*args): return _image.Image_read_bmp_file(*args)
> TypeError: Type error. Got dvac001.bmp, expected _p_std__string
>
> How can I call this function from Python? I would be very appreciative 
> for any help.
>
> With kind regards
(Continue reading)


Gmane