[C++-sig] [Boost.Python] imports and callbacks

Nat Goodspeed ngoodspeed at solidworks.com
Thu Nov 16 18:49:05 CET 2006


> -----Original Message-----
> From: c++-sig-bounces+ngoodspeed=solidworks.com at python.org
[mailto:c++-
> sig-bounces+ngoodspeed=solidworks.com at python.org] On Behalf Of Tanguy
> Fautre
> Sent: Thursday, November 16, 2006 11:49 AM
> To: c++-sig at python.org
> Subject: [C++-sig] [Boost.Python] imports and callbacks
> 
> The interpreter however complains that math.cos is unknown (i.e.
> ignoring the "import math;" at the beginning of the python code).
> 
> If I uncomment #import math in the event_callback definition,
everything
> works fine.

[Nat] When you invoke Python from C++, are you passing the same dict for
locals and globals?

Whatever you're passing for globals and locals when you evaluate the
class definition, are you passing the same two dicts when you re-enter
the registered handler?

I had a similar issue in which I simply wanted to run a customization
script. I prepopulated one dict (I think globals) and passed an empty
dict for locals. My inline script code worked fine -- but when I started
trying to define functions and classes in the script, the nested code
stopped being able to reference my global symbols.

I fixed it by passing the same dict for both.



More information about the Cplusplus-sig mailing list