Consider a class which can represent itself as a string: class Foo { public: std::string toString() { return "foo"; } }; This is wrapped thus: class_< Foo, boost::shared_ptr<Foo> >("Foo", "The Foo class" ) .def(init< >()) .def("toString", &Foo::toString ) .def("__repr__", &Foo::toString ) ; When imported into python, I get different return values calling Foo::toString() compared to when I let python get the return value implicitly:
from foo_ext import * f = Foo() f.toString() 'foo' f foo
Why does the explicit call to Foo::toString() return a properly quoted string while the implicit call invoked by python does not? How should I wrap Foo such that both ways of getting the string representation return the same thing (a quoted string)? db
That's the expected behaviour ! I'm sure you'll have :
print f.toString() foo
Python _print_ the string returned by __repr__ or __str__. But if you return a string it will print repr(string) ! On Thu, 2004-04-29 at 17:41, Dave Berton wrote:
Consider a class which can represent itself as a string:
class Foo { public: std::string toString() { return "foo"; } };
This is wrapped thus:
class_< Foo, boost::shared_ptr<Foo> >("Foo", "The Foo class" ) .def(init< >()) .def("toString", &Foo::toString ) .def("__repr__", &Foo::toString ) ;
When imported into python, I get different return values calling Foo::toString() compared to when I let python get the return value implicitly:
from foo_ext import * f = Foo() f.toString() 'foo' f foo
Why does the explicit call to Foo::toString() return a properly quoted string while the implicit call invoked by python does not? How should I wrap Foo such that both ways of getting the string representation return the same thing (a quoted string)?
db
_______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
I get the following error message when running my Python module after building everything (but Python) with gcc 3.4.0... ImportError: /lib/libgcc_s.so.1: version `GCC_3.3' not found (required by /usr/local/lib/libstdc++.so.6) Running the same C++ code with a main program, i.e. not via Python/boost, there's no problem. Any clues? Some things I've tried... There's a libgcc_s.so.1 installed in /usr/local/lib. So I try setting LD_LIBRARY_PATH (which I don't normally set) to /usr/local/lib. Then running my program from Python via Boost crashes initializing the first basic_string. Or, in another variation of my program in initiaizing an ifstream with the debugger looking for ../../../../gcc-3.3.3/stdc++v3/ios.cc This source file is not on my machine, so it seems to say I'm linking against a library in /usr/lib which is incompatible with my build of gcc in /usr/local/lib.
I cannot tell what is wrong, but I can tell that I am using Boost.Python with gcc 3.4.0 all the time without any problems under RedHat 8. I am working with /usr/bin/python (2.2.1) as it ships with RedHat 8; this python was compiled with gcc 3.2. Ralf P.S.: I am only doing extending, not embedding. --- "Paul F. Kunz" <Paul_Kunz@slac.stanford.edu> wrote:
I get the following error message when running my Python module after building everything (but Python) with gcc 3.4.0...
ImportError: /lib/libgcc_s.so.1: version `GCC_3.3' not found (required by /usr/local/lib/libstdc++.so.6)
Running the same C++ code with a main program, i.e. not via Python/boost, there's no problem. Any clues?
Some things I've tried...
There's a libgcc_s.so.1 installed in /usr/local/lib. So I try setting LD_LIBRARY_PATH (which I don't normally set) to /usr/local/lib. Then running my program from Python via Boost crashes initializing the first basic_string. Or, in another variation of my program in initiaizing an ifstream with the debugger looking for
../../../../gcc-3.3.3/stdc++v3/ios.cc
This source file is not on my machine, so it seems to say I'm linking against a library in /usr/lib which is incompatible with my build of gcc in /usr/local/lib.
__________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree
On Thu, 29 Apr 2004 09:48:07 -0700 (PDT), "Ralf W. Grosse-Kunstleve" <rwgk@yahoo.com> said:
I cannot tell what is wrong, but I can tell that I am using Boost.Python with gcc 3.4.0 all the time without any problems under RedHat 8. I am working with /usr/bin/python (2.2.1) as it ships with RedHat 8; this python was compiled with gcc 3.2. Ralf P.S.: I am only doing extending, not embedding.
I just tried my SIP based module. Identical problem. I was thinking of re-compiling Python in /usr/local/ with 3.4, it was compiled with 3.3.x in /usr/local/.
--- "Paul F. Kunz" <Paul_Kunz@slac.stanford.edu> wrote:
I was thinking of re-compiling Python in /usr/local/ with 3.4, it was compiled with 3.3.x in /usr/local/.
I believe this makes a difference only if Python is configured --with-cxx, which I never do. Ralf __________________________________ Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover
On Thu, 29 Apr 2004 10:35:51 -0700 (PDT), "Ralf W. Grosse-Kunstleve" <rwgk@yahoo.com> said:
I believe this makes a difference only if Python is configured --with-cxx, which I never do. Ralf
Neither do I, didn't know the option existed :-).
"Paul F. Kunz" <Paul_Kunz@slac.stanford.edu> writes:
I get the following error message when running my Python module after building everything (but Python) with gcc 3.4.0...
Paul, Please see http://www.boost-consulting.com/boost/more/discussion_policy.htm#quoting on starting a new topic. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (5)
-
Dave Berton -
David Abrahams -
Paul F. Kunz -
Pierre Barbier de Reuille -
Ralf W. Grosse-Kunstleve