[C++-sig] Importing and internal modules

Peter LaDow petela at gocougs.wsu.edu
Mon Sep 29 23:32:37 CEST 2008


On Mon, Sep 29, 2008 at 2:07 PM, Ravi <lists_ravi at lavabit.com> wrote:
> Think about how this would work in pure python. When you import a module X,
> all modules/functions X depends on must be explicitly imported in X.py. You
> cannot import Y in the global interpreter namespace and somehow expect to
> inject the contents of X into Y even if X has already been imported into the
> global namespace. So what you are trying to do is impossible even in the pure
> python case. Why would you expect it to work here?

I was thinking that by passing 'globals' to both calls to import(),
symbols would be injected into the global namespace.  The goal is to
make a set of functions exported by the extension available to Python
scripting modules without the need for an explicit import statement.
It isn't a killer if that cannot occur, I was just attempting to make
things easier for the users of the extension.

> That said, you could inject the contents of foo into the dictionary of bar,
> but you will run into subtle problems later. Try prototyping this in pure
> python before attempting this from an extension module.

Fair enough.  I tried your example.  I'm no Python expert, and chose
Python because it was already popular amongst many people here at
work.  The difference with the Boost method, I thought, was the
passing of the 'globals' object to each of the imports, thinking that
symbols were injected into the dictionary, and that later imports
would see any previous imports.  I see your point.

Thanks for the feedback.  It appears my goal of exporting a set of
global "built-in" functions (a la TCL) is not possible.

Pete
-- 
--
"To love for the sake of being loved is human;  to love for the sake
of loving is Angelic."  -- Alphonse de Lamartine



More information about the Cplusplus-sig mailing list