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

Tanguy Fautre tanguy.fautre at spaceapplications.com
Fri Nov 17 10:52:56 CET 2006


Nat Goodspeed wrote:
>> -----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.


Yes, I'm using one global dict for all the scripts, and separate (empty) 
local dicts for each scripts.

I'll try your approach of using the global dict in place of the local 
one. For that, I'll need to create separate global dicts for each 
scripts then.


Tanguy




More information about the Cplusplus-sig mailing list