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

Ivan Illarionov ivan.illarionov at gmail.com
Wed Jan 14 19:03:35 CET 2009

On Jan 14, 8:17 pm, Ivan Illarionov <ivan.illario... at gmail.com> wrote:
> 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.

Sorry, I probably was terribly wrong in my last post, it doesn't work
this way with separate dictionaries. I never had to use separate
dictionaries. Maybe someone with better knowledge of Python internals
may help?


More information about the Python-list mailing list