[C++-sig] set python attribute from C++

David Abrahams dave at boostpro.com
Wed Jul 16 01:37:03 CEST 2008


on Tue Jul 15 2008, Gennadiy Rozental <rogeeff-AT-gmail.com> wrote:

> How can I set object attribute inside the function foo implementation. More
> generally: how can I get access ot the underlying python object?
>
> essentially I want something like this:
>
> void foo( A& obj )
> {
>    boost::python::object o = get_py_object( obj );
>    o.attr( "field" ) = 1;
> }

I think this works better than the other suggestions:

  void foo( boost::shared_ptr<A> a )
  {
      boost::python::object o(a);
      o.attr( "field" ) = 1;
  }

Please let me know if it works out.
-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com



More information about the Cplusplus-sig mailing list