[C++-sig] boost::python::str and Python's str and unicode types
Hello, I'm looking for some confirmation that my understanding of what boost.python is doing is correct. >From what I understand boost::python::str represents the str (PyStringObject) type in Python. Unless I'm missing something, here doesn't seem to be anything like boost::python::unicode representing the unicode type (PyUnicodeObject). Boost.Python does have a built-in conversion from std::wstring to object, but this creates a str in Python, so presumably there is some (lossy?) decoding going on here. It seems that to directly create a PyUnicodeObject from C++ I will need to do one or more of the following: 1) Directly use the Python C API to create and manipulate PyUnicodeObject. 2) Create my own subclass of boost::python::object called for example 'unicode', which would be similar to the str class provided out of the box, but would use PyUnicodeObject underneath and deal with wchar_t rather than char. Correct? Many thanks, Rob DISCLAIMER: This message contains information that may be privileged or confidential and is the property of the Roxar Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorised to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] boost::python::str and Python's str and unicode types
On 07/23/2009 10:17 AM, Robert Smallshire wrote: Hello, I'm looking for some confirmation that my understanding of what boost.python is doing is correct. > From what I understand boost::python::str represents the str (PyStringObject) type in Python. Unless I'm missing something, here doesn't seem to be anything like boost::python::unicode representing the unicode type (PyUnicodeObject). Boost.Python does have a built-in conversion from std::wstring to object, but this creates a str in Python, so presumably there is some (lossy?) decoding going on here. It seems that to directly create a PyUnicodeObject from C++ I will need to do one or more of the following: 1) Directly use the Python C API to create and manipulate PyUnicodeObject. 2) Create my own subclass of boost::python::object called for example 'unicode', which would be similar to the str class provided out of the box, but would use PyUnicodeObject underneath and deal with wchar_t rather than char. You might want to talk to Haoyu Bai, who is presently working on the Python 3 port of boost.python. I wonder whether some of his work would be useful with Python 2, notably the unicode stuff. Haoyu, any thoughts on this ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Boost.Python indexing suite version 2?
This is a sketch of what I want to do. This seems to work seamlessly with the included indexing suite. I cannot figure out how the make it work with the advanced one. -- c++ -- struct foo { int bar; }; class_("foo") .def_readwrite("bar", &foo::bar) ; #if 1 //this does not work the way I want class_< std::vector >("class_< std::vector >("VectorOfFoo") ) .def( indexing::container_suite< std::vector >() ) ; #else //I think this should work the way I want, but it will not compile. class_< std::vector >("VectorOfFoo") .def( indexing::container_proxy< std::vector >() ) ; #endif --Python -- v = VectorOfFoo() f = foo() f.bar = 0 v.append(f) assert v[0].bar == 0 v[0].bar = 10 #This returns the foo by value. That does not happen with the bp::vector_indexing_suite. assert v[0].bar == 10 # this fails. v[0].bar is still 0 -Original Message- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies@python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies@py thon.org] On Behalf Of Roman Yakovenko Sent: Wednesday, July 22, 2009 11:57 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost.Python indexing suite version 2? On Wed, Jul 22, 2009 at 11:00 PM, Matthew Scouten (TT) wrote: > I am looking into whether this will satisfy my needs. It looks good so > far but I have a question: > How am I supposed to use container_proxy? The only thing given for an > example is a link to an empty file. Using it as a drop-in replacement > for container_suite does not work. Unfortunately, I never used this class before. If you will send **small and complete** example of what you are trying to do, I will take a look on it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig