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

2010-01-04 Thread Simon Pickles

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(b);
   assert( c==2 );

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

Am I missing something?

Thanks

Si
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


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

2010-01-04 Thread Brian O'Kennedy
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 

> 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(b);
>   assert( c==2 );
>
> AttributeError: 'tuple' object has no attribute 'length'
>
> Am I missing something?
>
> Thanks
>
> Si
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

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

2010-01-04 Thread Stefan Seefeld

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(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
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


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

2010-01-04 Thread Simon Pickles

On 04/01/2010 14:02, Brian O'Kennedy wrote:

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




Thanks, thats perfect.


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] [boost.python] How can I link against certain python version?

2010-01-04 Thread blp330

Hi,

I try to upgrade my boost from 1.36 to 1.41, but it will link against
python26.lib.

My own python version is 2.5,

How can I tell boost to link with python25.lib?

Thanks.
-- 
View this message in context: 
http://old.nabble.com/-boost.python--How-can-I-link-against-certain-python-version--tp26984580p26984580.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig