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

Stefan Seefeld seefeld at sympatico.ca
Thu Jan 24 18:35:51 CET 2008


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...



More information about the Cplusplus-sig mailing list