From: Tomas W. <Tom...@hi...> - 2011-01-14 14:52:43
|
>From SWIG docs on std_string.i: "This module only supports types std::string and const std::string &. Pointers and non-const references are left unmodified and returned as SWIG pointers." I.e. if you change the C++ function so that it returns by const reference or by value you will end up getting a Python string object. This is a very good idea anyway since strings are supposed to be immutable in Python. /Tomas W. ________________________________________ Från: Ajay Kumar Todimala [aja...@gm...] Skickat: den 14 januari 2011 04:53 Till: swi...@li... Ämne: [Swig-user] Printing std:string & return param in python Folks, I have C++ function that I wrap in python using swig. The following is the function. std::string& GetText(strval aIndex) { return blocks[aIndex]; } My EXAMPLE.i swig file has std:string includes: %include <stl.i> %include <std_string.i> using std::string; using std; I am able to successfully call the function in python. but when try to print the return std:string & reference, >>> record_rrtr_info1 = record_rrtr.GetText(1) >>> >>> print record_rrtr_info1 <Swig Object of type 'std::string *' at 0x2b2b1b6f43c0> >>> print dir(record_rrtr_info1) ['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__hex__', '__init__', '__int__', '__le__', '__long__', '__lt__', '__ne__', '__new__', '__oct__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'acquire', 'append', 'disown', 'next', 'own'] How do I print this Swig Obj. Appreciate your help. Thanks, Ajay. |