Returning std::strnig does not give me back Python string

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Returning std::strnig does not give me back Python string

Alexander Botev
Hi, so I'm having the problem as described above. I have a member function of the form:

std::string to_string() const { ... }

which returns by value as suggested by the docs.
My swig file looks like this:
/* File : symbolic.i */
%module symbolic
%{
#include "symbolic.h"
%}
/* Let's just grab the original header file here */
%include "std_string.i"
%include "symbolic.h" 

However, when I call the method  on an object in Python 3 I get:

<Swig Object of type 'std::string *' at 0x7fd21be236c0>

rather than a normal Python string. I'm thinking that there is something very simple which I'm overlooking, but can't figure out what. I was hoping someone can point out to me?

Best regards,
Alex
 

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Returning std::strnig does not give me back Python string

William S Fulton
On 11 June 2016 at 12:50, Alexander Botev <[hidden email]> wrote:

> Hi, so I'm having the problem as described above. I have a member function
> of the form:
>
>> std::string to_string() const { ... }
>
>
> which returns by value as suggested by the docs.
> My swig file looks like this:
>>
>> /* File : symbolic.i */
>> %module symbolic
>> %{
>> #include "symbolic.h"
>> %}
>> /* Let's just grab the original header file here */
>> %include "std_string.i"
>> %include "symbolic.h"
>
>
> However, when I call the method  on an object in Python 3 I get:
>
>> <Swig Object of type 'std::string *' at 0x7fd21be236c0>
>
>
> rather than a normal Python string. I'm thinking that there is something
> very simple which I'm overlooking, but can't figure out what. I was hoping
> someone can point out to me?
>
Your code looks okay. All I can think of is to_string is overloaded in
some way or you are using some really ancient version of SWIG. Comment
out %include "symbolic.h" and replace it with a simplified version of
the class that contains to_string, eg:

struct MyStruct {
  std::string to_string() const { return "hi there"; }
};

and try again. Post a standalone example if you are still having problems.

William

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...