[C++-sig] [boost.python] __dict__ question
Robert
rcdailey at gmail.com
Thu Oct 9 20:02:49 CEST 2008
Hi,
Is it really necessary to obtain __dict__ in order to add variables to
some object's scope? For example, suppose I want to define a global
variable in a module, how would I do this? I know the first step I must
take is to import the module:
boost::python::import( "my_module" )
What then? A pseudo-code example of what I would expect is something like:
using namespace boost::python;
import( "my_module" ).attr( "my_global" ) = object( 5.0f );
What's the real way to do this? The only valid code I can come up with is:
using namespace boost::python;
object my_global( 5.0f );
dict my_module_namespace = extract<dict>( import( "my_module" ).attr(
"__dict__" ) );
my_module_namespace.append( my_global );
Is there no way to clean this up? I'm not even sure if this functions (I
haven't compiled it), but it should work I think.
More information about the Cplusplus-sig
mailing list