On 01/04/2010 08:53 AM, Simon Pickles wrote:
Hello,

I have a simple question. How do I find out in c++ how many elements are contained within a boost::python::tuple?

I tried this:

       using namespace boost::python;
       tuple a = make_tuple("hello", 42);
       object b = a.attr("length"); // exception
       unsigned int c = extract<unsigned int>(b);
       assert( c==2 );

AttributeError: 'tuple' object has no attribute 'length'

Am I missing something?

The attribute is spelled "__len__", not "length", and the pythonic way to call it is "len(a)". Thus:

tuple a = ...;
unsigned int c = len(a);

should work fine.

    Stefan

--

      ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to