'Import sys' succeeds in C++ embedded code, but module is not fully visible

Ivan Illarionov ivan.illarionov at gmail.com
Wed Jan 14 18:17:54 CET 2009


On Jan 14, 8:00 pm, Ben Sizer <kylo... at gmail.com> wrote:
> I will try it when I get home. However I would like to be able to
> treat them as separate dictionaries, as I want to be able to import
> some symbols and modules at a global level, but be able to clear out
> objects introduced at the local level on a periodic basis, so that I
> can have some degree of isolation between distinct 'scripts'. The docs
> aren't terribly clear about what the globals and locals parameters to
> PyRun_String actually do, though.
>
> I also wonder if this is something specific to the sys module, since
> it's already been shown that there are some specific C API functions
> for it. I will try with other modules and see if they exhibit the same
> symptoms.

After quick testing it looks like '__builtins__' must be in locals
dictionary for your embed Python code to work, it may be a separate
dictionary from globals though.

>From what I know 'sys' module is related to builtins. My knowledge of
Python internals is not so deep to explain the details of this
relationship and answer your question about sys.path[0] though.

--
Ivan



More information about the Python-list mailing list