Boost logo

Boost :

From: Ralf W. Grosse-Kunstleve (rwgk_at_[hidden])
Date: 2008-03-21 19:08:23


In C++?
I don't know the most elegant solution, but one that should work
easily is to convert the set to a boost::python::list, maybe (untested):

  void
  foo(boost::python::object s)
  {
    boost::python::list l(s);
    long n = boost::python::len(l);
    for(long i=0;i<n;i++) {
      boost::python::extract<int> proxy(l[i]);
      int v = proxy();
    }
  }

Probably, a more efficient solution is to use PyObject_GetIter() and
PyIter_Next(), but to make this safe you have to mess with
boost::python::handle<> and PyErr_Clear(). Look here for a related example:

http://phenix-online.org/cctbx_sources/scitbx/include/scitbx/boost_python/container_conversions.h

Ralf

----- Original Message ----
From: Gennadiy Rozental <rogeeff_at_[hidden]>
To: boost_at_[hidden]
Sent: Friday, March 21, 2008 11:45:18 AM
Subject: [boost] [python] set iteration

How do I iterate over object that correspond to python set?

Gennadiy

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk