[C++-sig] Boost Python Tuple - Find length of tuple?

Brian O'Kennedy brokenn at gmail.com
Mon Jan 4 15:02:13 CET 2010


You could try this instead: (untested!)

      using namespace boost::python;
      tuple a = make_tuple("hello", 42);
      std::cout << "Length = " << boost::python::len(a) << std::endl;  //
explicit namespace not needed

hth,
 Brian

2010/1/4 Simon Pickles <sipickles at googlemail.com>

> 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?
>
> Thanks
>
> Si
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100104/cf7f23b3/attachment.htm>


More information about the Cplusplus-sig mailing list