make tuple of tuples in embedding python?
In Python/C API PyTuple can have different types of items. For example, pTuple = PyTuple_New(3); PyTuple_SetItem(pTuple, 0, pString1); PyTuple_SetItem(pTuple, 1, pString2); PyTuple_SetItem(pTuple, 2, pDict); I would like to know if I can make tuple of tuples for embedding Python in C++. For example, pTuple0 = PyTuple_New(3); pTuple1 = PyTuple_New(3); pTuple2 = PyTuple_New(3); pTupleOfTuple = PyTuple_New(3); PyTuple_SetItem(pTupleOfTuple, 0, pTuple0); PyTuple_SetItem(pTupleOfTuple, 1, pTuple1); PyTuple_SetItem(pTupleOfTuple, 2, pTuple2); It seems the code can be compiled. But, it would crash as long as it starts running without any output info. So, I could not know what is wrong. Thanks in Advance, ZZ
ZiZi Zhao wrote:
In Python/C API PyTuple can have different types of items. For example,
pTuple = PyTuple_New(3); PyTuple_SetItem(pTuple, 0, pString1); PyTuple_SetItem(pTuple, 1, pString2); PyTuple_SetItem(pTuple, 2, pDict);
I would like to know if I can make tuple of tuples for embedding Python in C++. For example,
pTuple0 = PyTuple_New(3); pTuple1 = PyTuple_New(3); pTuple2 = PyTuple_New(3);
pTupleOfTuple = PyTuple_New(3);
PyTuple_SetItem(pTupleOfTuple, 0, pTuple0); PyTuple_SetItem(pTupleOfTuple, 1, pTuple1); PyTuple_SetItem(pTupleOfTuple, 2, pTuple2);
It seems the code can be compiled. But, it would crash as long as it starts running without any output info. So, I could not know what is wrong.
I'm not sure this answers your question, but since you ask on this particular list, here is how you do the above with boost.python: namespace bpl = boost::python; bpl::tuple t0 = bpl::make_tuple("hello", "world", bpl::dict()); bpl::tuple t1 = bpl::make_tuple("hi !", t0); HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin...
Stefan, thank you for your reply that does answer my question, although I used python/c++ API and you are using boost:python. plus, my application may go more complex like: tuple of tuple of strings tuple of integers tuple of dicts tuple of tuples if boost-python is more flexible & stable, I may try it alos. but, I don't see many sample codes of embedding python using boost-python. there is only one sampel in their document. THANKS, ZZ -----Original Message----- From: c++-sig-bounces@python.org on behalf of Stefan Seefeld Sent: Tue 2/27/2007 6:59 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] make tuple of tuples in embedding python? ZiZi Zhao wrote:
In Python/C API PyTuple can have different types of items. For example,
pTuple = PyTuple_New(3); PyTuple_SetItem(pTuple, 0, pString1); PyTuple_SetItem(pTuple, 1, pString2); PyTuple_SetItem(pTuple, 2, pDict);
I would like to know if I can make tuple of tuples for embedding Python in C++. For example,
pTuple0 = PyTuple_New(3); pTuple1 = PyTuple_New(3); pTuple2 = PyTuple_New(3);
pTupleOfTuple = PyTuple_New(3);
PyTuple_SetItem(pTupleOfTuple, 0, pTuple0); PyTuple_SetItem(pTupleOfTuple, 1, pTuple1); PyTuple_SetItem(pTupleOfTuple, 2, pTuple2);
It seems the code can be compiled. But, it would crash as long as it starts running without any output info. So, I could not know what is wrong.
I'm not sure this answers your question, but since you ask on this particular list, here is how you do the above with boost.python: namespace bpl = boost::python; bpl::tuple t0 = bpl::make_tuple("hello", "world", bpl::dict()); bpl::tuple t1 = bpl::make_tuple("hi !", t0); HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig
On 2/28/07, ZiZi Zhao <zzhao@laika.com> wrote:
Stefan,
thank you for your reply that does answer my question, although I used python/c++ API and you are using boost:python. plus, my application may go more complex like:
tuple of tuple of strings tuple of integers tuple of dicts tuple of tuples
if boost-python is more flexible & stable, I may try it alos. but, I don't see many sample codes of embedding python using boost-python. there is only one sampel in their document.
There is a lot of examples. Take a look on this for example: http://svn.python.org/view/stackless/sandbox/examples/embedding/watchdog-cpp/main.cpp?rev=52182&view=markup Also if you search this mailing list, I am sure you will find dozen of them. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
Thanks a lot! ZZ -----Original Message----- From: c++-sig-bounces@python.org on behalf of Roman Yakovenko Sent: Wed 2/28/2007 10:18 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] make tuple of tuples in embedding python? On 2/28/07, ZiZi Zhao <zzhao@laika.com> wrote:
Stefan,
thank you for your reply that does answer my question, although I used python/c++ API and you are using boost:python. plus, my application may go more complex like:
tuple of tuple of strings tuple of integers tuple of dicts tuple of tuples
if boost-python is more flexible & stable, I may try it alos. but, I don't see many sample codes of embedding python using boost-python. there is only one sampel in their document.
There is a lot of examples. Take a look on this for example: http://svn.python.org/view/stackless/sandbox/examples/embedding/watchdog-cpp/main.cpp?rev=52182&view=markup Also if you search this mailing list, I am sure you will find dozen of them. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig
participants (3)
-
Roman Yakovenko -
Stefan Seefeld -
ZiZi Zhao