[C++-sig] HOWTO: ...create shallow boost::python::object copies ?

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Jan 24 19:46:11 CET 2008


Hi Stefan, look for "astute" on this page:
http://www.boost.org/libs/python/doc/tutorial/doc/html/python/object.html
Ralf

----- Original Message ----
From: Stefan Seefeld <seefeld at sympatico.ca>
To: c++-sig at python.org
Sent: Thursday, January 24, 2008 9:35:51 AM
Subject: [C++-sig] HOWTO: ...create shallow boost::python::object copies ?


I'm accessing python objects from within C++, using the convenient
bpl::object, bpl::list, etc. types. However, I just now realize that 
their constructors all (?) create new Python objects. How can I prevent
 
that ? Imagine this python code:


d = o.__dict__
d['new_member'] = 42
print o.new_member

which I would like to write in C++:

bpl::dict d = o.attr("__dict__")
d["new_member"] = 42

However, as 'd' is a copy of o's __dict__ attribute, the new_member 
never makes it into o. How can I do what I want ?

(Yes, in this case I obviously wouldn't need the indirection over 'd'; 
this is just a minimal test case...)

Thanks,
        Stefan


-- 

       ...ich hab' noch einen Koffer in Berlin...
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig






More information about the Cplusplus-sig mailing list